Please Help with this error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dv_evan
Forum Commoner
Posts: 42
Joined: Wed Apr 09, 2008 8:23 am

Please Help with this error

Post by dv_evan »

Everah | Please use code tags when posting code in the forums.

Dear Developers,

Have developed a simple code to access MySQL on a local machine and it worked well. When I upload it to the webserver host I am getting this:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in line 14

here is the code

Code: Select all

<?php
include ("DBcon.php");
 
$query = "select * from booth_table WHERE Name_of_Co ='' ORDER BY Booth_No ";
$result=mysql_query($query);
 
mysql_close();
 
//this is line 14
$num=mysql_num_rows($result);
 
$i=0;
while($i<$num){
$output=mysql_result($result,$i,"Booth_No");
 
 
            echo "Booth No: $output <br> ";
            $i++;
            }
 
?>

Kindly advise what to do.
Thanks
Dave
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: Please Help with this error

Post by jaoudestudios »

You are getting an error because $result is empty, your query is not returning any results.

Do a search on the forum I have discussed this many times before with other developers.
Paul Arnold
Forum Contributor
Posts: 141
Joined: Fri Jun 13, 2008 10:09 am
Location: Newcastle Upon Tyne

Re: Please Help with this error

Post by Paul Arnold »

Change this line:

$result=mysql_query($query);

To

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

And you should receive an error message with more specific information about why your query is not returning any results.
Remember to change the line back once you've fixed the problem though otherwise people may see specific information about your database structure which is a security issue.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Please Help with this error

Post by RobertGonzalez »

Thread moved to PHP Code from General discussion (because this is not a general discussion but a PHP code one).
Post Reply