An error occurred while using mysqli_fetch_object in PHP.

Source: Internet
Author: User
{Code ...} there is only one record in the database. When I query the account & #039; 13 & #039;, I am prompted that the password returned in my php code is incorrect. When I query the account & #039; 1a & #039; the following error is reported: Is there a problem with my database or some other reasons? I use the statement {code in phpmyadmin ....
Mysqli_select_db ($ con, "my_2db"); // SELECT the operating database $ query = 'select password FROM user WHERE account = '. $ account; // define an SQL query statement $ result = mysqli_query ($ con, $ query); // send an SQL query if ($ obj = mysqli_fetch_object ($ result )) // obtain the query result

There is only one record in the database.


When I query account = '13', follow the prompts that the password returned by my php code is incorrect. When I query account = '1a ', an error is returned.
The following error is reported:


Is there a problem with my database or some other reasons? I use the statement in phpmyadmin

SELECT password FROM user WHERE account='13'

And

SELECT password FROM user WHERE account='1a'

They all have the same results and are not properly queried.

Reply content:
Mysqli_select_db ($ con, "my_2db"); // SELECT the operating database $ query = 'select password FROM user WHERE account = '. $ account; // define an SQL query statement $ result = mysqli_query ($ con, $ query); // send an SQL query if ($ obj = mysqli_fetch_object ($ result )) // obtain the query result

There is only one record in the database.


When I query account = '13', follow the prompts that the password returned by my php code is incorrect. When I query account = '1a ', an error is returned.
The following error is reported:


Is there a problem with my database or some other reasons? I use the statement in phpmyadmin

SELECT password FROM user WHERE account='13'

And

SELECT password FROM user WHERE account='1a'

They all have the same results and are not properly queried.

The query statement is incorrect,

 $query='SELECT password FROM user WHERE account='.$account;

Note the character writing method when it contains letters.

 $query='SELECT password FROM user WHERE account='.'"'.$account.'"';

There is a situation:mysqli_queryWhen querying account = '1a ', the query fails.mysqli_queryReturns a Boolean value.false, Andmysqli_fetch_objectThe first parameter of ismysqli_resultObject

After you can perform the query,var_dump($result)View query results

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.