Warning: mysql_num_rows() error

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

Warning: mysql_num_rows() error

Post 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
thegreatone2176
Forum Contributor
Posts: 102
Joined: Sun Jul 11, 2004 1:27 pm

Post by thegreatone2176 »

add

or die(mysql_error());

to the end of your $query

the nums rows isnt working because your query is bugged somewhere
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

Post by ljCharlie »

Thanks! I tried that but no difference. Same error.

ljCharlie
thegreatone2176
Forum Contributor
Posts: 102
Joined: Sun Jul 11, 2004 1:27 pm

Post 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
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

Post 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
thegreatone2176
Forum Contributor
Posts: 102
Joined: Sun Jul 11, 2004 1:27 pm

Post 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.
MrKnight
Forum Newbie
Posts: 22
Joined: Fri Jan 28, 2005 8:54 am
Location: Another Planet

Post 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
Post Reply