Error extracting data with alphabetic user name

Source: Internet
Author: User
After the user logs in, I use the following statement to extract the data of the logged-on user:
Include ("incdb.php");
Session_Start ();
$result =mysql_query ("select * from Userlinks where id= ' A02 ' and userid= '." $_session[' id '). "ORDER BY datetime desc LIMIT 1" , $link);
$row = Mysql_fetch_row ($result);
echo "$row [1]";
Echo
";
echo "$row [2]";

Mysql_close ($link);
?>

The problem is that when a full-digital user logs in, the extracted data is displayed correctly, but if the user name contains letters or characters, the display is empty, nothing is present, and also reported is wrong: Warning:mysql_fetch_row (): supplied argument is not a valid MySQL result resource in .... Why?

My database and Web pages are all UTF-8 encoded. There is data in the database, not empty. Thank you, I'm going crazy ....


Reply to discussion (solution)

The extracted data is displayed correctly when a full-digital user logs on, but if the user name contains letters or kanji, the display is empty and nothing is also reported wrong: Warning:mysql_fetch_row (): supplied argument is not a valid MySQL Result resource in ....

String to enclose in quotation marks, this is common sense!

$result =mysql_query ("select * from Userlinks where id= ' A02 ' and userid= '." $_session[' id '). "ORDER BY datetime desc LIMIT 1" , $link) or Die (Mysql_error ());

$result =mysql_query ("select * from Userlinks where id= ' A02 ' and userid= '". $_session[' id '). ' ORDER BY datetime desc LIMIT 1 ", $link);

Is this more clear?

$result = mysql_query ("select * from Userlinks where id= ' A02 ' and userid= ' $_session[id] ' ORDER BY datetime desc LIMIT 1", $ link);

I am really a rookie, please forgive me. I don't know much. The difference is whether the session should use single quotes, and I use the double quotation marks? But I see people upstairs also reply with double quotes Ah.

I used the quotation mark ~ ~

Is it more than that piece of code behind the die?

Userid= ' AA ' here the AA needs to be enclosed in quotation marks, both single and double quotes.

Your echo, your SQL is clear.

Brother, I have the original quotation marks AH.
$result =mysql_query ("select * from Userlinks where id= ' A02 ' and userid= '." $_session[' id '). "ORDER BY datetime desc LIMIT 1" , $link);

Userid= ". $_session[' id ']." Order
Where is the quotation mark that encloses the value of $_session[' ID ' in the SQL directive?
All you have is to assemble the quotation marks of the PHP string

$_session[' id ' = ' abc123 '; $sql = "SELECT * from Userlinks where id= ' A02 ' and userid= '." $_session[' id ']. "ORDER BY DateTime DESC LIMIT 1 "; Echo $sql; See for yourself if the value of the UserID field is enclosed in quotation marks.

Brother A look is a master. Is that supposed to happen?
$result =mysql_query ("select * from Userlinks where id= ' A02 ' and userid= '". $_session[' id ']. " ' ORDER BY datetime desc LIMIT 1 ', $link);
Do I need to add a single quote? I am very food, and very stupid, trouble ah.

I am the forum on the mobile phone, I remember that I also put the quotation marks, as if not.

Thank you xuzuning and jordan102 two elder brother!! If it can be solved, can I give two people 30?

Userid= ' ". $_session[' id ')." ' Order this is not going to work
To Userid= ' ". $_session[' id ')." ' Order this
Otherwise, there's a space and I can't find it.

Can I give two people 30?
No, unless you add points to the post!

Okay, I got it. If I go back to the test and solve it, it must be extra points. Thank you

$result =mysql_query ("select * from Userlinks where id= ' A02 ' and userid= '." $_session[' id '). "ORDER BY datetime desc LIMIT 1" , $link);

Switch

$result =mysql_query ("select * from Userlinks where id= ' A02 ' and userid= '". $_session[' id ']. " ' ORDER BY datetime desc LIMIT 1 ', $link);

Thanks to Xuzuning and jordan102 and Fdipzone, it has been solved. Thank you!

Why am I only 10 points available? As if can only increase 10 points, give xuzuning and jordan102 each 20. Not enough next time to fill up.

  • 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.