Page 1 of 1

mysql_fetch_array() expects parameter 1 to be resource

Posted: Tue Sep 29, 2009 12:33 am
by nehrav
Hi friends,

I am getting this error : 8O

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\test\edit.php on line 11

with this code

<?php
$con = mysql_connect("localhost","new","test");
$db = mysql_select_db("test",$con);


$select = mysql_query("select * from table");

echo "<table border='0' cellpadding='0'
cellspacing='0' width='500'>";

while($result = mysql_fetch_array($select))
{
$id = $result['id'];
$name = $result['name'];

$age = $result['age'];

$salary = $result['salary'];

echo "<tr><td>$name</td><td>$age</td><td>$salary</td
><td><A HREF='delete.php?name=$name'>DELETE</A></td><td><A
HREF='update.php'>UPDATE</A></td></tr>";

}
echo "</table>";


?>

Re: mysql_fetch_array() expects parameter 1 to be resource

Posted: Tue Sep 29, 2009 3:44 am
by robnet
Hi Nehrav,
First, can you surround your code in [ php]code[ /php] tags (Without the space after '[')? it makes long extracts of code much easier to read by code highlighting, auto scrolling and numbering lines.

Second, it looks like the query isn't working. use mysql_error() to see the specific error, then paste it back here if you aren't sure where to go from there.
http://uk2.php.net/mysql_error

For example try this:

Code: Select all

$select = mysql_query("select * from table") or die(mysql_error());