【问题标题】:mysql_fetch_array() expects parameter 1 to be resource, boolean given in, and a [duplicate]mysql_fetch_array() 期望参数 1 是资源、布尔值和 [重复]
【发布时间】:2015-05-10 06:56:47
【问题描述】:

我收到以下错误:

警告:mysql_fetch_array() 期望参数 1 是资源, 在

中给出的布尔值

警告:无法修改标头信息 - 标头已由 (输出开始于“插入文件”中的“在此处插入文件位置” 位置“在线”

这是我的代码

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

【问题讨论】:

  • 尝试 var_dump($result3);结果如何?
  • 尝试删除正确的数据 mysql_connect("itekniks.net","itekniks_wcc","wccantipolo") 这可能是对您的数据库或网站的攻击威胁

标签: php mysql sql select fetch


【解决方案1】:
<?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

【讨论】:

  • 我也试过了,它给了我相同的输出“'where 子句中的未知列'reservation_id'”是因为数据库中没有reservation_id?抱歉这个菜鸟问题,我对 php 不是很有经验:/ 感谢您的回复!
  • @Patrick 只需将其作为答案,谢谢帕特
  • 检查过了,我应该在数据库上添加一个 reservation_id 吗?再次感谢。
  • @Patrick 是的,只需添加它,但您应该知道您在那里创建的 room_id 和消息 id 的连接
  • 感谢您的帮助和提示!它现在启动并运行:)
【解决方案2】:

首先,您只需打印$result3 并查看它返回的内容。

另外,你可以试试:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-20
    • 1970-01-01
    • 2013-07-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多