943,917 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1946
  • PHP RSS
May 31st, 2006
0

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

Expand Post »
[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 "<b>You have not selected search details. Please go back and try again.</b>";
}
else
{

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

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 "<tr>\n";
echo "<td align=left>\n";
echo "<p> Student ID: ".$IDNo."";
echo "<br>Student Name: ".$sName."";
echo "<br>Starting Date: ".$startDate."";
echo "<br>Ending Date: ".$endDate."";
echo "<br>Student Phone: ".$sPhone."";
echo "<br>P.O.Box: ".$OBox."";
echo "<br>Bus number: ".$busNo."";
echo "</p>";
echo "</td></tr>\n";

echo "\n";
echo "\n";
echo "</table>\n";
}

}
}
?>
[inlinecode]
[/php]

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

please can you help me to find the error
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Zayed is offline Offline
3 posts
since May 2006
May 31st, 2006
0

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

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.
Reputation Points: 10
Solved Threads: 1
Light Poster
BlazingWolf is offline Offline
32 posts
since Feb 2006
May 31st, 2006
0

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

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

I got this message "Query was empty"

Wat does this mean?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Zayed is offline Offline
3 posts
since May 2006
May 31st, 2006
0

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

[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:
Quote ...
select * from STUDENT where busNo like 'select busNo from BUS where place like 'Foobar''
Try running that by itself :-|
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cdwhalley.com is offline Offline
5 posts
since May 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: help in faqs
Next Thread in PHP Forum Timeline: PHP e-mail SMTP error ???





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC