Php error prompt: mysql_fetch_row (): suppliedargumentisnotavalidMySQL-php Tutorial

Source: Internet
Author: User
Php error prompt: mysql_fetch_row (): suppliedargumentisnotavalidMySQL tests the database connection Today. the following error occurs when the information in the data table is traversed:

Warning: mysql_fetch_row (): supplied argument is not a valid MySQL result resource in D: \ AppServ \ www \ wordpress \ lianjie001.php on line 20

The original code I wrote is as follows:


$ Db_host = "localhost ";
$ Db_database = "wordpress ";
$ Db_username = "root ";
$ Db_password = "admin123 ";
$ Connection = mysql_connect ($ db_host, $ db_username, $ db_password );
Mysql_query ("set names 'utf8 '");

$ SQL = "select * from huanzhexinxi ";
$ Result = mysql_query ($ SQL );

While ($ resultrowzhen = mysql_fetch_row ($ result ))){
$ Huanname = $ resultrowzhen [0];
$ Huanage = $ resultrowzhen [1];
$ Huancall = $ resultrowzhen [2];
$ Huanliu = $ resultrowzhen [3];
Echo"";
Echo"Name: $ huanname
";
Echo"Age: $ huanage
";
Echo"Tel: $ huancall
";
Echo"Patient message: $ huanliu
";
Echo"
";
}


Mysql_close ($ connection );
?>



After half a day of check, no error was found. my colleague pointed out that the database selection code was missing, as shown below:

$ Db_selecct = mysql_select_db ($ db_database );

The complete code is as follows.



$ Db_host = "localhost ";
$ Db_database = "wordpress ";
$ Db_username = "root ";
$ Db_password = "admin123 ";
$ Connection = mysql_connect ($ db_host, $ db_username, $ db_password );
Mysql_query ("set names 'utf8 '");
$ Db_selecct = mysql_select_db ($ db_database );
$ SQL = "select * from huanzhexinxi ";
$ Result = mysql_query ($ SQL );

While ($ resultrowzhen = mysql_fetch_row ($ result ))){
$ Huanname = $ resultrowzhen [0];
$ Huanage = $ resultrowzhen [1];
$ Huancall = $ resultrowzhen [2];
$ Huanliu = $ resultrowzhen [3];
Echo"";
Echo"Name: $ huanname
";
Echo"Age: $ huanage
";
Echo"Tel: $ huancall
";
Echo"Patient message: $ huanliu
";
Echo"
";
}


Mysql_close ($ connection );
?>


Reply to discussion (solution)

Are you sure you want to ask? Or do you want to share your experience?

The closing rate is 0. it is estimated that it was just a whim.

It is better to teach people to fish than to teach them to fish.
Echo mysql_error ();

Mysql_query ($ SQL) or die (mysql_error ());

Solution on the 4th floor .........

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.