Reputation: 29
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.0\www\List.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>
Upvotes: 1
Views: 3487
Reputation: 43830
The error means you had an error in your sql, make sure you escape it before using it because you might become victim of sql injection.
$sql = "SELECT * FROM students WHERE seconds=%d";
$sql = sprintf($sql,mysql_real_escape_string($S));
make sure you have the correct data in $S;
$result = mysql_query($sql) or die("Error: ".mysql_error());
and this way you will know what is your exact error.
Upvotes: 0
Reputation: 6127
Basically Error like Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given..
means that your query result is wrong. mysql_query
instead of returning result returns false
, which means your query is wrong.
Simple check what's wrong using:
$sql = "select * from students where Sec=$S ";
# V ADDED
$result = mysql_query($sql) or die( mysql_error() );
Upvotes: 0
Reputation: 2371
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()
}
Upvotes: 2
Reputation: 50019
Your mysql_query($sql)
call is probably returning false
. You need to see if your script managed to connect to your mysql server
From the manual : http://php.net/manual/en/function.mysql-query.php
if (!$result) {
die('Invalid query: ' . mysql_error());
}
Upvotes: 1