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

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

问题描述


可能存在重复:

警告:mysql_fetch_array()期望参数1为资源,布尔值为”错误,而尝试创建一个PHP购物车


我不明白,我在代码中看到没有错误,但是有这个错误,请帮助:

mysql_fetch_array()期望参数1成为资源问题

 <?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 =aborder =0align =centercellpadding =0cellspacing =1bgcolor =#D3D3D3>
< tr>

< td>
< table border =0cellpadding =3cellspacing =1bgcolor =>
< tr>

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


< tr>
< td width =30height =35>< font size =2> * I D编号:< / td>
< td width =30>< input name =idnumonkeypress =return isNumberKey(event)type =textmaxlength =5id ='numbers'/ value = <?php echo $ _GET ['id'];?>>< / td>
< / tr>

< tr>
< td width =30height =35>< font size =2> *年份:< / td>
< td width =30>< input name =yronkeypress =return isNumberKey(event)type =textmaxlength =5id ='numbers'/ value = <?php echo $ row [YEAR];?>>< / td>

<?php}?>

我只是试图加载表单中的数据,但我不知道为什么会出现这种错误出现。这可能是什么错误?

在解析 之后,您没有进行错误检查 mysql_query

  $ result = mysql_query(SELECT * FROM student WHERE IDNO =。$ _ GET ['id']); 
if(!$ result){//添加此检查。
die('Invalid query:'。mysql_error());

$ / code>

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


Possible Duplicate:
“Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given” error while trying to create a php shopping cart

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?

解决方案

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

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天全站免登陆