Mysql_fetch_array () expects parameter 1 to be resource

Source: Internet
Author: User
$host = "localhost";
$user = "root";
$password = "123456";

$connection = Mysqli_connect ($host, $user, $password);
if (! $connection) {
Exit (' Failed to connect to MySQL database! ');
}

$dbname = "Chuanke";

mysqli_select_db ($connection, $dbname);

$sql = "SELECT * from ' user '";
$result = Mysqli_query ($connection, $sql);

while ($row =mysqli_fetch_array ($result))
{
echo $row [' UserName ']. "
";
}

?>
This time tip: notice:undefined index
Then I changed the while ($row =mysqli_fetch_array ($result)) to while ($row =mysql_fetch_array ($result))
This time the error becomes: mysql_fetch_array () expects parameter 1 to be resource,


Reply to discussion (solution)


Open Error_report,
Ini_setting ("Display_errors", 1);
Each line of code is var_dump a bit. You'll almost be able to locate the problem.


The ability to strengthen the debug base.

while ($row = Mysql_fetch_array ($result, Mysql_assoc)) {

Alas, the whole day is my careless echo $row [' UserName '].
"; [' UserName '] should be [' UserName '] or thank you upstairs. Two-bit Help

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