Page 1 of 1

Warning: mysql_num_rows() error

Posted: Tue Feb 01, 2005 3:13 pm
by ljCharlie
We were using PHP 4.0.6 and we upgraded to PHP 5.0.3. I am getting the following error:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in F:\wwwroot\home\myName\evtSearchPage.php on line 171

Line 171 is this line:

Code: Select all

$num_results = mysql_num_rows($result);
The code below is my query.

Code: Select all

$query = "select * from event where Month like '%".$slMonth."%' And Year like '%".$year."%' ORDER BY Day";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);

ljCharlie

Posted: Tue Feb 01, 2005 3:23 pm
by thegreatone2176
add

or die(mysql_error());

to the end of your $query

the nums rows isnt working because your query is bugged somewhere

Posted: Tue Feb 01, 2005 3:27 pm
by ljCharlie
Thanks! I tried that but no difference. Same error.

ljCharlie

Posted: Tue Feb 01, 2005 3:30 pm
by thegreatone2176
i read your code wrong sorry put this

Code: Select all

$result = mysql_query($query) or die(mysql_error());
that will show you the error and copy and paste what it says if you cant get it

Posted: Tue Feb 01, 2005 3:35 pm
by ljCharlie
The error is "No database selected" this time.
Here's how I connect to my database.

Code: Select all

@ $db = mysql_connect("localhost", "username", "password");			
		if (!$db) {
			echo "Error: Could not connect to database. Please try again later.";
			exit;
			}
		mysql_select_db("alumni");

ljCharlie

Posted: Tue Feb 01, 2005 3:46 pm
by thegreatone2176
you could try sticking the die statement after the select_db.

im pretty sure this means you are picking a non-existant database. Most of the time there is a database prefix check sql server for it.

Posted: Wed Feb 02, 2005 9:17 am
by MrKnight
maybe problem is not with these lines, maybe with the query that you send db, paste it here code here and also look at this link http://bugs.mysql.com/bug.php?id=4391