Questions about the Mysql_query return value

Source: Internet
Author: User
Error code
   
Can run code
 
       
 
       All UsersAdd user
 
    "; for ($i =1; $i < $dataCount; $i + +) {    $result _arr=mysql_fetch_assoc ($result);    $id = $result _arr[' id '];    $name = $result _arr[' name '];    $age = $result _arr[' age ');    echo "$id $name$age ' > Modify
' > Delete ';} echo "";? >

The return value of mysql_query in two pieces of code, but why a function has a warning when it calls its return value


Reply to discussion (solution)

"SELECT * from users WHERE name= $name and password= $password"

The above code is problematic, name and password are not quoted, resulting in a SQL syntax error, no return to the resource type, and a Boolean value of False
The correct code should be
"SELECT * from Users WHERE ' name ' = $name and ' password ' = $password"

$sql = "SELECT * from users WHERE name= $name and password= $password";

Switch

$sql = "SELECT * from Users WHERE name= '". $name. "' and password= ' ". $password." ";

Because you $name, $password if empty, it can cause a syntax error.

Or is it wrong? To try to change the SQL statement again, it should be that $name and $password are not treated as strings causing an error ...

"SELECT * from Users WHERE ' name ' =". $name. " and ' password ' = ". $password

Or is it wrong? To try to change the SQL statement again, it should be that $name and $password are not treated as strings causing an error ...

"SELECT * from Users WHERE ' name ' =". $name. " and ' password ' = ". $password



I wrote it wrong again ... That should be it.
"SELECT * from Users WHERE name= '". $name. "' and password= ' ". $password." ";


Or is it wrong? To try to change the SQL statement again, it should be that $name and $password are not treated as strings causing an error ...

"SELECT * from Users WHERE ' name ' =". $name. " and ' password ' = ". $password



I wrote it wrong again ... That should be it.
"SELECT * from Users WHERE name= '". $name. "' and password= ' ". $password." ";

Can you tell me why

$sql = "SELECT * from users WHERE name= $name and password= $password";

Switch

$sql = "SELECT * from Users WHERE name= '". $name. "' and password= ' ". $password." ";

Because you $name, $password if empty, it can cause a syntax error.

Can you tell me why?



Or is it wrong? To try to change the SQL statement again, it should be that $name and $password are not treated as strings causing an error ...

"SELECT * from Users WHERE ' name ' =". $name. " and ' password ' = ". $password



I wrote it wrong again ... That should be it.
"SELECT * from Users WHERE name= '". $name. "' and password= ' ". $password." ";

Can you tell me why



Because $name and $password should appear as strings in SQL statements (that is, single quotes wrap up $name and $password values)

Or do you want to know why you want to do that? Single and double quotes?




Or is it wrong? To try to change the SQL statement again, it should be that $name and $password are not treated as strings causing an error ...

"SELECT * from Users WHERE ' name ' =". $name. " and ' password ' = ". $password



I wrote it wrong again ... That should be it.
"SELECT * from Users WHERE name= '". $name. "' and password= ' ". $password." ";

Can you tell me why



Because $name and $password should appear as strings in SQL statements (that is, single quotes wrap up $name and $password values)

Or do you want to know why you want to do that? Single and double quotes?

I'd like to know why I'm stitching single and double quotes and why we have to put variables in the. The middle of the two points is what the role of

$sql = "SELECT * from users WHERE name= $name and password= $password";
If the $name and $password variables are numeric, you can use them directly in SQL statements, and if you are a variable of type string, you need to add single quotes

I split the code into three paragraphs, and you should be able to understand. The two point is used to concatenate strings, meaning to tell PHP that the variable after the point is a string

"SELECT * from Users WHERE name= '"

"' and password= '"

"'"

That is, when each single quote/double quote touches the second single quotation mark/double quote, that segment of the character ends. These three paragraphs are all in a double quote parcel quotation mark.

I split the code into three paragraphs, and you should be able to understand. The two point is used to concatenate strings, meaning to tell PHP that the variable after the point is a string

"SELECT * from Users WHERE name= '"

"' and password= '"

"'"

That is, when each single quote/double quote touches the second single quotation mark/double quote, that segment of the character ends. These three paragraphs are all in a double quote parcel quotation mark.

Yes, thank you.
  • 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.