View Full Version : valid MySQL result resource Error, Need Help

06-11-2010, 06:31 PM

$con1 = mysql_connect("localhost","uname","pass");

if (!$con1)
die('Could not connect: ' . mysql_error());

if ($con1)
echo "<h5>Connection Success!</h5>";

mysql_select_db("jrmsport_verify", $con1);

$sql="SELECT * FROM Verify";

$result = mysql_query($sql);
while($row = mysql_fetch_array($result))

echo $row['Item'];



Would someone be able to tell me why I'm getting the error

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home2/jrmsport/public_html/verifyTest.php on line 27

I get a successful connection to the sql server, my database is called jrmsport_verify and my table is called Verify.
Just doesn't make sense to me, as this exact code has worked for me in the past with different db connections. Thanks for the help.

06-11-2010, 06:33 PM
$result = mysql_query($sql) or die(mysql_error());

06-11-2010, 10:01 PM
Is your table Verify or verify? Is your column named Item or item?

*nix is case sensitive, windows is not.

06-12-2010, 05:48 PM
Do this to check result of sql query:

$result = mysql_query($sql) or die(mysql_error());

and be careful and check for this

Is your table Verify or verify? Is your column named Item or item?

*nix is case sensitive, windows is not.

also you can try
sql="SELECT * FROM `Verify`";
, because i am not quite sure, but `Verify` can be reserved word.

06-13-2010, 07:44 PM
$result = mysql_query($sql) or die(mysql_error());

This results in:

"No database selected"

The cases of my table and all columns match up.

Any ideas?

EDIT: After adding the single quotes around Verify as saviola suggested, I now get this error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''Verify'' at line 1

06-14-2010, 07:58 AM
Verify isn't a reserved word and you need to use backticks not single quotes around the table name. Backtick is the button above your tab button. The problem I believe is it is not selecting the database at mysql_select_db("jrmsport_verify", $con1) and therefore the mysql_query function needs a link to connect to resulting in an invalid resource on the fetch statement.


mysql_select_db("jrmsport_verify", $con1) or die(mysql_error());

The user may not have access to your database or it may be misspelled.