您好!
当我运行我的代码时这个问题出现了
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\Program Files (x86)\EasyPHP-5.3.5.0\www\List.php on line 28
这是我的密码
<?php
session_start();
?>
<html>
<link rel='stylesheet' type='text/css' href='Style.css'>
<title>Registration</title>
<body>
<?php
$S=$_POST['Sec'];
echo "<H4>Web Development a</H4>";
echo "<b>CS <br>Registration Page </b><br><br><br><br>";
echo "<b>This is the students lists who are registered in section $S: <br><br>";
echo "<table border=1 width=50%><tr><td width='6'></td><td bgcolor='#E66C2C' width='150'><b><center><font
color='#FFFFFF'>Name</center></td><td bgcolor='#E66C2C' width='100'><b><center><font
color='#FFFFFF'>ID</center></td>". "<td bgcolor='#E66C2C' width='100'><b><center><font color='#FFFFFF'>E-Mail</center></td></tr>";
include('con_db.php');
$sql = "select * from students where Sec=$S ";
$result = mysql_query($sql);
$i=0;
while ($r = mysql_fetch_array($result)) {
$i++;
echo "<tr><td bgcolor='#eae5a7' width='6'>";
echo "<b><center>".$i."</center><br>";
echo"</td>";
echo "<td width='150'>";
echo "<b><center>".$r[Fname]."</center><br>" ;
echo "</td>";
echo "<td width='100'>";
echo "<b><center>".$r[ID]."</center><br>" ;
echo "</td>";
echo "<td width='100'>";
echo "<b><center>".$r[mail]."</center><br>" ;
echo "</td></tr>";
echo "</font>";
}
echo"</table>";
echo "<form name='form' method='post' action='Registration_List.php'>";
?>
<br><br><center><input type='submit' id='send' value='Back' style="color: #FFFFFF; background-color: #E66C2C; border-width: 1; border-style: 1" ></form>
<?php
echo "<form name='form' method='post' action='ass1.php'>";
?>
<input type='submit' id='send' value='Home Page' style="color: #FFFFFF; background-color: #E66C2C; border-width: 1; border-style: 1"></form></center></td></tr></table>
</body>
</html>
最佳答案
重写如下:
$result = mysql_query($sql);
$i=0;
while ($r = mysql_fetch_array($result)) {
变成:
if($result = mysql_query($sql)){
$i=0;
while ($r = mysql_fetch_array($result)) {
...
}
} else {
//do something with mysql_error()
}
关于php - mysql中的错误获取php中的错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5910687/