php - mysql_fetch_array() 期望参数 1 为资源、给定的 bool 值和一个

标签 php mysql sql select fetch

<分区>

我收到以下错误:

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

关于php - mysql_fetch_array() 期望参数 1 为资源、给定的 bool 值和一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30148575/

相关文章:

PHP - 如何加载新闻文章?

php - 如何在 laravel 原始查询方法中连接列数组?

php - 在 Yii2 中设置非规范化列的最佳实践

php - MySQL - 如何在多列html表中显示,mysql表的单列

sql - PostgreSQL:获取 jsonb 数组中对象的值以进行全文搜索

php - 从开关“中断”,然后循环中的 'continue'

php - PHP将变量传递给register_shutdown_function- fatal error 处理程序

mysql - 列出所有项目的项目编号、项目名称和员 worker 数 > 2 名员工参与其中

sql - 外部表不刷新数据雪花

php - MySQL - 从房间到公寓的多对一 : how to get the lowest priced room for an apartment without having to iterate through all the rooms?