[Resolved]php query MySQL returned the wrong result

Source: Internet
Author: User
Keywords Php mysql
Tags mysql query
This is about the reason why Chinese characters are not supported: After you have changed all the properties of MySQL to English characters, use MySQL well.
But! Write with mysqli or will return empty (again measured, password box does not enter or enter 0 will be successful login prompt)
It all dawned on him that the return result of result was wrong. Then use the Mysqli_fetch_array to remove the elements to be used just fine.

PHP part of the code is as follows: No output connection to the database information (should be successful) no error apache2 and MySQL log error logs also have no information. However: The result returned value of the query is always null. (Of course the other password will show the password error re-login)
However, the password I set for them in MySQL has already been modified to be equal to the account value. Why would I return the wrong information? is the query written incorrectly?

@ $db=new mysqli ('localhost','webdba','123456','educational_administration');        if(mysqli_connect_errno())        {            echo"error".mysqli_connect_errno().":无法连接到数据库";            exit();        }        //echo "success";        if($user_type=='teacher')        {            $query="select 密码 from teacher where 教师编号=$user_id";            if(!$query){echo'此用户不存在.点击重新登录';}            $result=$db->query($query);            //echo $result.'
'; if($result!=$passwd) { echo '密码错误
'; $db->close(); echo '点击重新登录 '; } else {echo $user_id.'已成功登录
';} }

Reply content:

This is about the reason why Chinese characters are not supported: After you have changed all the properties of MySQL to English characters, use MySQL well.
But! Write with mysqli or will return empty (again measured, password box does not enter or enter 0 will be successful login prompt)
It all dawned on him that the return result of result was wrong. Then use the Mysqli_fetch_array to remove the elements to be used just fine.

PHP part of the code is as follows: No output connection to the database information (should be successful) no error apache2 and MySQL log error logs also have no information. However: The result returned value of the query is always null. (Of course the other password will show the password error re-login)
However, the password I set for them in MySQL has already been modified to be equal to the account value. Why would I return the wrong information? is the query written incorrectly?

@ $db=new mysqli ('localhost','webdba','123456','educational_administration');        if(mysqli_connect_errno())        {            echo"error".mysqli_connect_errno().":无法连接到数据库";            exit();        }        //echo "success";        if($user_type=='teacher')        {            $query="select 密码 from teacher where 教师编号=$user_id";            if(!$query){echo'此用户不存在.点击重新登录';}            $result=$db->query($query);            //echo $result.'
'; if($result!=$passwd) { echo '密码错误
'; $db->close(); echo '点击重新登录 '; } else {echo $user_id.'已成功登录
';} }

First of all:
if (! $query) {echo ' This user does not exist. Click Re-login ';}
This is always false, the back will never output

Secondly:
$result = $db->query ($query);
The return should be the array, should be $RESULT0 this structure

I do not know your query in the Chinese is intentionally written in this way or this is the case, you can print the query statement, and then in the MySQL query once you know

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.