mysql_fetch_array() 期望参数 1 为资源、给定的布尔值和一个

mysql_fetch_array() expects parameter 1 to be resource, boolean given in, and a

我收到以下错误:

Warning : mysql_fetch_array() expects parameter 1 to be resource, boolean given in

Warning: Cannot modify header information - headers already sent by (output started at "Insert file location here" in "Insert File location here"on line

这是我的代码

<?php
    if (isset($_GET['id']))
    {
        $con = mysql_connect("xxx.net","username","password") or die("Connection to server Failed");
        if (!$con)
        {
            die('Could not connect: ' . mysql_error());
        }

        mysql_select_db("itekniks_altaroca") or die("DB Selection Failed");
        $messages_id = $_GET['id'];
        $result3 = mysql_query("SELECT * FROM reservation where reservation_id ='$messages_id'");


        while($row3 = mysql_fetch_array($result3))
        {
            $res=$row3['confirmation'];
        }
        $update1=mysql_query("UPDATE reservation SET status ='out' WHERE reservation_id ='$messages_id'");
        $update2=mysql_query("UPDATE roominventory SET status ='out' WHERE confirmation = '$res'");
        header("location: home_admin.php#1");

        exit();

        mysql_close($con);
    }
?>
<?php
    if (isset($_GET['id']))
    {
        $con = mysql_connect("xxxx.net","username","password") or die("Connection to server Failed");
        if (!$con)
        {
            die('Could not connect: ' . mysql_error());
        }

        mysql_select_db("xxxxdb") or die("DB Selection Failed");
        $messages_id = $_GET['id'];
        $result = mysql_query("SELECT * FROM reservation where reservation_id ='$messages_id'");

        if($result === FALSE) { 
            die(mysql_error()); // TODO: better error handling
        }

        while($row3 = mysql_fetch_array($result3))
        {
            $res=$row3['confirmation'];
        }
        $update1=mysql_query("UPDATE reservation SET status ='out' WHERE reservation_id ='$messages_id'");
        $update2=mysql_query("UPDATE roominventory SET status ='out' WHERE confirmation = '$res'");
        header("location: home_admin.php#1");

        exit();

        mysql_close($con);
    }
?>

也许你在那里选择了未定义的reservation table。或者有 no column reservation_id


mysql_fetch_array

之前添加这个
        if($result === FALSE) { 
            die(mysql_error()); // TODO: better error handling
        }

在这里更新了我的代码:

<?php
    if (isset($_GET['id']))
    {
        $con = mysql_connect("xxxx.net","username","password") or die("Connection to server Failed");
        if (!$con)
        {
            die('Could not connect: ' . mysql_error());
        }

        mysql_select_db("xxxxdb") or die("DB Selection Failed");
        $messages_id = $_GET['id'];
        $result = mysql_query("SELECT * FROM reservation where reservation_id ='$messages_id'");

        if($result === FALSE) { 
            die(mysql_error()); // TODO: better error handling
        }

        $row = mysql_fetch_array($result);
        $confirmation = $row['confirmation'];
        $update1=mysql_query("UPDATE reservation SET status ='out' WHERE reservation_id ='$messages_id'");
        $update2=mysql_query("UPDATE roominventory SET status ='out' WHERE confirmation = '$confirmation'");
        header("location: home_admin.php#1");

        exit();

        mysql_close($con);
    }
?>
  1. 您的预订中没有第 reservation_id 列 table

首先你只需要打印 $result3 看看它是什么 returns.

另外,你可以试试:

$result3 = mysql_query("SELECT * FROM reservation where reservation_id=".$messages_id);