Skip to content
Advertisement

Error in mysql fetch error in php

Hi when i run my code this proplem apper

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:Program Files (x86)EasyPHP-5.3.5.0wwwList.php on line 28

this is my code

<?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>

Advertisement

Answer

rewrite so this:

$result = mysql_query($sql);
$i=0;

while ($r = mysql_fetch_array($result)) {

becomes this:

if($result = mysql_query($sql)){
    $i=0;

   while ($r = mysql_fetch_array($result)) {
   ...
   }
} else {
   //do something with mysql_error()
}      
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement