•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 391,615 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,627 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1419 | Replies: 3
![]() |
•
•
Join Date: May 2006
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in
#1
May 31st, 2006
[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
[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
•
•
Join Date: Feb 2006
Posts: 32
Reputation:
Rep Power: 3
Solved Threads: 1
Re: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in
#2
May 31st, 2006
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.
[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.
•
•
Join Date: May 2006
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
Re: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in
#3
May 31st, 2006
Re: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource
#4
May 31st, 2006
[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:
Try running that by itself :-|
$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''
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
Similar Threads
- Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource (PHP)
- Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in (PHP)
- Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource (PHP)
Other Threads in the PHP Forum
- Previous Thread: help in faqs
- Next Thread: Printing from Php


Linear Mode