PDA

Click to See Complete Forum and Search --> : More mySQL Problems [Resolved]


mendhak
May 16th, 2003, 06:09 AM
I have mySQL running on my computer here, and all works fine: using PHP I can enter data, and view it.

However, on the server, it just won't work.

I keep getting this error:



Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home/mendhak/public_html/slambook/view.php on line 23


The code I'm using is



$dbh=mysql_connect("localhost", "mendhak_hello", "zzz") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db("slambook");




$abcquery = "SELECT * FROM slambook;";

$result = mysql_query($abcquery);

echo $result;






$rowsonthispage = mysql_numrows($result); //this is line 23, where the error is occuring



echo "There are $rowsonthispage rows in total";
mysql_close();



I've also tried using mysql_num_rows, and I still get the same error. Now, it's obvious there's a problem with what $result is retrieving, but why is that? The query is perfectly fine. The database name is slambook, and the table name is also slambook... is that causing problems?

What can I do to resolve this problem?

The Hobo
May 16th, 2003, 10:47 AM
'...

mysql_select_db("slambook") or die(mysql_error());

$abcquery = "SELECT * FROM slambook;";

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

echo $result;

'...

Do that and see if it produces a different error.

Also, a few things:

[list=1]
You don't need to put a ; at the end of your MySQL queries.
You don't need to use mysql_close(), as this is done automatically when the script finishes executing.
[/list=1]

phpman
May 16th, 2003, 11:03 AM
yes, that semi-colon is the problem

$abcquery = "SELECT * FROM slambook;";

also it is good practice to make your names different than you db name.

mendhak
May 17th, 2003, 05:36 AM
Resolved! The die(mysql_error()) thing really helped: I saw that I had to select the db "mendhak_slambook" instead of just "slambook"


Thanks a lot. :)