...

View Full Version : what does this error annoucement mean?



kusa
10-11-2004, 06:13 AM
hi!!!
What does it mean in this error announcement?
/*
Film Search Results

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in c:\phpdev\www\foreveryoung\searching.php on line 17

Number of films found:
*/
Can you explain more about the command:
mysql_num_rows()
Thanks

hemebond
10-11-2004, 06:18 AM
It returns the number of records returned by a query.

http://us2.php.net/manual/en/function.mysql-num-rows.php

Celtboy
10-11-2004, 04:48 PM
usually means something is awry in your SQL query. (Either it isn't properly structured, and/or is returning 0 results)

Try echoing your SQL statement to make sure it is correct.

kusa
10-16-2004, 12:10 PM
I do try the command line with my Database, it works ... :thumbsup:
however, there is one problem with the connection from the html page to the php one..
I need your help in detecting the error:
here is the html script:
<form action="resultsb.php" method="post">

<h3 style="color:#ffffff">Choose search Type:</h3>
<br>
<select name="searchtype">
<option value="title">Film title</option>
<option value="director">Director</option>
<option value="presentingdate">Showing Date</option>
</select>
<br>
<h3 style="color:#ffffff">Enter Search Term:</h3>
<br>
<input name="searchterm" type="text">
<br>
<br>
<input type="submit" value="Search">
</form>
And here is the php script:
<?php
trim($searchterm);
if (!$searchtype ||!$searchterm)
{
echo "You have not entered search details.Please go back and try again.";
exit;
}

$searchtype=addslashes($searchtype);
$searchterm=addslashes($searchterm);

$db= mysql_connect("localhost");

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

mysql_select_db("test");
$query="SELECT * FROM film WHERE ".$searchtype. "like '%".$searchterm. "%'";
$result= mysql_query($query);
$num_results=mysql_num_rows($result);
echo "<p>Number of films found: ".$num_results."</p>";
for ($i=0; $i<$num_results; $i++)
{
$row= mysql_fetch_array($result);
echo "<p><strong>".($i+1).". Title:";
echo htmlspecialchars(stripslashes($row["title"]));
echo "</strong><br>Director: ";
echo htmlspecialchars(stripslashes($row["director"]));
echo "<br>Presenting Date:";
echo htmlspecialchars(stripslashes($row["presentingdate"]));
echo"</p>";
}

?>

kusa
10-16-2004, 12:11 PM
I do try the command line with my Database, it works ... :thumbsup:
however, there is one problem with the connection from the html page to the php one..
I need your help in detecting the error:
here is the html script:
<form action="resultsb.php" method="post">

<h3 style="color:#ffffff">Choose search Type:</h3>
<br>
<select name="searchtype">
<option value="title">Film title</option>
<option value="director">Director</option>
<option value="presentingdate">Showing Date</option>
</select>
<br>
<h3 style="color:#ffffff">Enter Search Term:</h3>
<br>
<input name="searchterm" type="text">
<br>
<br>
<input type="submit" value="Search">
</form>
And here is the php script:
<?php
trim($searchterm);
if (!$searchtype ||!$searchterm)
{
echo "You have not entered search details.Please go back and try again.";
exit;
}

$searchtype=addslashes($searchtype);
$searchterm=addslashes($searchterm);

$db= mysql_connect("localhost");

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

mysql_select_db("test");
$query="SELECT * FROM film WHERE ".$searchtype. "like '%".$searchterm. "%'";
$result= mysql_query($query);
$num_results=mysql_num_rows($result);

echo "<p>Number of films found: ".$num_results."</p>";

for ($i=0; $i<$num_results; $i++)
{
$row= mysql_fetch_array($result);
echo "<p><strong>".($i+1).". Title:";
echo htmlspecialchars(stripslashes($row["title"]));
echo "</strong><br>Director: ";
echo htmlspecialchars(stripslashes($row["director"]));
echo "<br>Presenting Date:";
echo htmlspecialchars(stripslashes($row["presentingdate"]));
echo"</p>";
}

?>

kusa
10-16-2004, 12:20 PM
I do try the command line with my Database, it works ... :thumbsup:
however, there is one problem with the connection from the html page to the php one..I need your help in detecting the error:
here is the html script:
<form action="resultsb.php" method="post">

<h3 style="color:#ffffff">Choose search Type:</h3>
<br>
<select name="searchtype">
<option value="title">Film title</option>
<option value="director">Director</option>
<option value="presentingdate">Showing Date</option>
</select>
<br>
<h3 style="color:#ffffff">Enter Search Term:</h3>
<br>
<input name="searchterm" type="text">
<br>
<br>
<input type="submit" value="Search">
</form>
And here is the php script:
<?php
trim($searchterm);
if (!$searchtype ||!$searchterm)
{
echo "You have not entered search details.Please go back and try again.";
exit;
}

$searchtype=addslashes($searchtype);
$searchterm=addslashes($searchterm);

$db= mysql_connect("localhost");

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

mysql_select_db("test");
$query="SELECT * FROM film WHERE ".$searchtype. "like '%".$searchterm. "%'";
$result= mysql_query($query);
$num_results=mysql_num_rows($result);

echo "<p>Number of films found: ".$num_results."</p>";

for ($i=0; $i<$num_results; $i++)
{
$row= mysql_fetch_array($result);
echo "<p><strong>".($i+1).". Title:";
echo htmlspecialchars(stripslashes($row["title"]));
echo "</strong><br>Director: ";
echo htmlspecialchars(stripslashes($row["director"]));
echo "<br>Presenting Date:";
echo htmlspecialchars(stripslashes($row["presentingdate"]));
echo"</p>";
}

?>
I think it gets wrong from the connection between html and php site, because I try to print out the $searchterm before and after the trim() function, it doesn't appear anything..Beside,when I drop the checking value whether the user fill up the text form or not(if (!$searchtype ||!$searchterm)
{
echo "You have not entered search details.Please go back and try again.";
exit;
}

)
an error message appears on the screen:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in c:\phpdev\www\foreverlove\resultsb.php on line 25

Number of films found:
Thank you!!! :p



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum