PHP error Hint: mysql_fetch_row (): supplied argument is not a valid MySQL

Source: Internet
Author: User
Tags php error
Today the test database connection, traversing the data table in the information is the following error has occurred:

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

The code I originally wrote was this:


$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);
?>



Check the half-day also did not find errors, and then peer guidance is missing the code to select the database is as follows:

$db _selecct=mysql_select_db ($db _database);

The complete code is the following to complete the traversal.



$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)

Is this the question? Or do you want to share your experience?

The knot rate is 0, it's an impulse to come and play.

To give a man to fish is better than to teach
Echo Mysql_error ();

mysql_query ($sql) or Die (Mysql_error ());

4 Floor positive solution ....

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