mysql_fetch_array() 期望参数 1 是资源问题 [英] mysql_fetch_array() expects parameter 1 to be resource problem

查看:25
本文介绍了mysql_fetch_array() 期望参数 1 是资源问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
“警告:mysql_fetch_array() 期望参数 1 为资源,布尔值给定"尝试创建 php 购物车时出错

我不明白,我看这段代码没有错误,但是有这个错误,请帮忙:
mysql_fetch_array() 期望参数 1 是资源问题

I don't get it, I see no mistakes in this code but there is this error, please help:
mysql_fetch_array() expects parameter 1 to be resource problem

<?php

      $con = mysql_connect("localhost","root","nitoryolai123$%^");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }

    mysql_select_db("school", $con);
       $result = mysql_query("SELECT * FROM student WHERE IDNO=".$_GET['id']);
    ?>     


                           <?php while ($row = mysql_fetch_array($result)) { ?>             
                                     <table class="a"  border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#D3D3D3">
    <tr>

    <form name="formcheck" method="get" action="updateact.php" onsubmit="return formCheck(this);">
    <td>
    <table  border="0" cellpadding="3" cellspacing="1" bgcolor="">
    <tr>

    <td  colspan="16" height="25"  style="background:#5C915C; color:white; border:white 1px solid; text-align: left"><strong><font size="2">Update Students</td>


    <tr>
    <td width="30" height="35"><font size="2">*I D Number:</td>
    <td width="30"><input  name="idnum" onkeypress="return isNumberKey(event)" type="text" maxlength="5" id='numbers'/ value="<?php echo $_GET['id']; ?>"></td>
    </tr>

    <tr>
    <td width="30" height="35"><font size="2">*Year:</td>
    <td width="30"><input  name="yr" onkeypress="return isNumberKey(event)" type="text" maxlength="5" id='numbers'/ value="<?php echo $row["YEAR"]; ?>"></td>

<?php } ?>

我只是想在表单中加载数据,但我不知道为什么会出现该错误.这里可能有什么错误?

I'm just trying to load the data in the forms but I don't know why that error appears. What could possibly be the mistake in here?

推荐答案

在调用 mysql_query:

You are not doing error checking after the call to mysql_query:

$result = mysql_query("SELECT * FROM student WHERE IDNO=".$_GET['id']);
if (!$result) { // add this check.
    die('Invalid query: ' . mysql_error());
}

如果 mysql_query 失败,它返回 false,一个 boolean 值.当你把它传递给 mysql_fetch_array 函数(它需要一个 mysql 结果对象)时,我们会得到这个错误.

In case mysql_query fails, it returns false, a boolean value. When you pass this to mysql_fetch_array function (which expects a mysql result object) we get this error.

这篇关于mysql_fetch_array() 期望参数 1 是资源问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆