Page 1 of 1

Please Help with this error

Posted: Tue Jul 29, 2008 10:18 pm
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

Re: Please Help with this error

Posted: Wed Jul 30, 2008 2:25 am
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.

Re: Please Help with this error

Posted: Wed Jul 30, 2008 5:44 am
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.

Re: Please Help with this error

Posted: Thu Jul 31, 2008 12:16 pm
by RobertGonzalez
Thread moved to PHP Code from General discussion (because this is not a general discussion but a PHP code one).