An error occurred while extracting username data containing letters.

Source: Internet
Author: User
An error occurred while extracting username data with letters. after a user logs on, I use the following statement to extract the data of the user who has logged on:
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 the extracted data can be correctly displayed when a full number of users log on, but if the user name contains letters or Chinese characters, the displayed content is blank and there is nothing; and an error is returned: Warning: mysql_fetch_row (): supplied argument is not a valid MySQL result resource in .... why?

My database and web pages are all coded in UTF-8. The database contains data, not empty. Thank you! I'm going crazy ....


Reply to discussion (solution)

When a digital user logs on, the extracted data is displayed correctly. if the user name contains letters or Chinese characters, the displayed content is null, nothing is displayed, and the following error is returned: Warning: mysql_fetch_row (): supplied argument is not a valid MySQL result resource in ....

It is common sense to enclose strings in quotation marks!

 $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 clearer?

$result = mysql_query("SELECT * FROM userlinks where id='a02' and userid='$_SESSION[id]' order by datetime desc limit 1",$link);

I am a Cainiao. sorry. I don't know much about it. The difference is that the session should use single quotes, but I use double quotes ?. However, some people on the building replied with double quotation marks.

I used the quotation marks ~~

Is there a piece of code that follows die?

Userid = 'a' aa must be enclosed in quotation marks. single quotation marks and double quotation marks are acceptable.

Your echo and your SQL statements are clear.

Brother, I used to have quotation marks.
$ Result = mysql_query ("SELECT * FROM userlinks where id = 'a02' and userid = ". $ _ SESSION ['id']. "order by datetime desc limit 1", $ link );

Userid = ". $ _ SESSION ['id']." order
In the SQL command, where are the quotation marks for the value of $ _ SESSION ['id?
All you have is the quotation marks for assembling php strings.

$ _ SESSION ['id'] = 'abc123'; $ SQL = "SELECT * FROM userlinks where id = 'a02' and userid = ". $ _ SESSION ['id']. "order by datetime desc limit 1"; echo $ SQL; // check whether the value of the userid field is enclosed by quotation marks.

Brother is a master. Should this be the case?
$ Result = mysql_query ("SELECT * FROM userlinks where id = 'a02' and userid = '". $ _ SESSION ['id']. "'Order by datetime desc limit 1", $ link );
I need to add a single quotation mark, right? I am very stupid and troublesome.

I am a forum on a mobile phone. I remember that I also put quotation marks on it. it seems that I cannot.

Thank you, xuzuning and jordan102 !! If I can solve this problem, can I give each of them 30?

Userid = '". $ _ SESSION ['id']." 'Order is not acceptable.
Userid = '". $ _ SESSION ['id']." 'Order
Otherwise, an extra space will be missing.

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

Okay, I see. If I go back to the test to solve the problem, I will definitely add points. Thank you.

$ Result = mysql_query ("SELECT * FROM userlinks where id = 'a02' and userid = ". $ _ SESSION ['id']. "order by datetime desc limit 1", $ link );

Change

$ Result = mysql_query ("SELECT * FROM userlinks where id = 'a02' and userid = '". $ _ SESSION ['id']. "'Order by datetime desc limit 1", $ link );

Thanks to xuzuning, jordan102, and fdipzone, it has been solved. Thank you!

Why am I only available at 10? It seems that only 10 points can be added, and xuzuning and jordan102 will be given 20 points each. Not enough.

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.