954,132 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

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

[code]
[php]
<?php
$SearchType = $_POST["SearchPlace"];
$host= 'localhost';
$user= 'user';
$passwd= 'password';
$database= 'dbase';
$table1= 'BUS';
$table2= 'STUDENT';

$connect= mysql_connect($host, $user, $passwd);
mysql_select_db($database);
$pquery = "select busNo from $table1 where place like '".$SearchType."'";

$squery = "select * from $table2 where busNo like '".$pquery."'";

$run = mysql_query($squery);
$num_results = mysql_num_rows($run);




if (!$SearchType )
{
echo "You have not selected search details. Please go back and try again.";
}
else
{

if (!$connect)
{
echo"Error: Could not connect to database. Please try again later.";
}

else
{
for ($i=0; $i<$num_results; $i++)
{
$row = mysql_fetch_array($run);

$IDNo= stripslashes($row["IDNo"]);
$sName= stripslashes($row["sName"]);
$startDate= stripslashes($row["startDate"]);
$endDate = stripslashes($row["endDate"]);
$sPhone= stripslashes($row["sPhone"]);
$OBox= stripslashes($row["OBox"]);
$busNo= stripslashes($row["busNo"]);

echo "\n";
echo "\n";
echo " Student ID: ".$IDNo."";
echo "
Student Name: ".$sName."";
echo "
Starting Date: ".$startDate."";
echo "
Ending Date: ".$endDate."";
echo "
Student Phone: ".$sPhone."";
echo "
P.O.Box: ".$OBox."";
echo "
Bus number: ".$busNo."";
echo "


";
echo "\n";

echo "\n";
echo "\n";
echo "\n";
}

}
}
?>
[inlinecode]
[/php]

Hi I am getting this warning and I don't know why?!! :sad: :!:

please can you help me to find the error

Zayed
Newbie Poster
3 posts since May 2006
Reputation Points: 10
Solved Threads: 0
 

Your query is probably failing. Try

[php]$run = mysql_query($squery) or die(mysql_error());[/php]

And see if you get an error.

Or echo out your SQL statment and trying running it against the database.

BlazingWolf
Light Poster
32 posts since Feb 2006
Reputation Points: 10
Solved Threads: 1
 

I tried
[php]
$run = mysql_query($squery) or die(mysql_error());
[/php]

I got this message "Query was empty"

Wat does this mean?

Zayed
Newbie Poster
3 posts since May 2006
Reputation Points: 10
Solved Threads: 0
 

[PHP]
$pquery = "select busNo from $table1 where place like '".$SearchType."'";

$squery = "select * from $table2 where busNo like '".$pquery."'";
[/PHP]
If $_POST['searchplace'] was given as "Foobar" (for want of a better example), $squery would be set to:
select * from STUDENT where busNo like 'select busNo from BUS where place like 'Foobar''
Try running that by itself :-|

cdwhalley.com
Newbie Poster
5 posts since May 2006
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You