我不明白,我在这段代码中没有看到任何错误,但是有这个错误,请帮助: 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="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 } ?>
我只是试图在表单中加载数据,但不知道为什么会出现该错误。这里可能有什么错误?
调用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 result object)时,我们会收到此错误。
mysql_query
false
boolean
mysql_fetch_array
mysql result object