Page 1 of 1

error: Warning: mysql_fetch_array(): supplied argument is no

Posted: Wed Jan 18, 2012 6:27 pm
by buddyt
I am getting the following error when I run the code below. Please advise if you can tell me why. Thank you in advance.

Code: Select all

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource[ /code ]

Here's the code that's generating the error: 
[syntax="php" ]
<?php
$con = mysql_connect("*********","**********","**********");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  } 

$result = mysql_query("SELECT * FROM Users");
echo "<br />";
echo $result;

while($row = mysql_fetch_array($result))
  {
  echo $row['First_Name'] . " " . $row['Last_Name'];
  echo "<br />";
  }

mysql_close($con);

?>
[ /syntax]

Re: error: Warning: mysql_fetch_array(): supplied argument i

Posted: Thu Jan 19, 2012 6:47 am
by JohnK_UK
As the error message says, $result is not a valid resource, so your query must have failed. There's nothing wrong with the syntax, so maybe you don't have permission to run select queries, or maybe the Users table doesn't exist. (Is it perhaps called users?) In any case, inserting

Code: Select all

if (!$result) {
    die('Invalid query: ' . mysql_error());
}
after the query should point you in the right direction.

FWIW, it's good practice ALWAYS to check the validity of a resource before trying to use it.

Re: error: Warning: mysql_fetch_array(): supplied argument i

Posted: Thu Jan 19, 2012 5:04 pm
by buddyt
John, Thanks for your post. What seemed to be the problem was that I was missing "mysql_select_db("buddytip", $con);" because when I added that the problem went away.