Posted by:
Catling
(---.cable.ubr01.telf.blueyonder.co.uk)
Could you take a quick look at my script please as I have been scratching my head for two days now as to why I can not get it to work.
<html>
<body>
<?php
//create short variable names
$searchtype=$_REQUEST['searchtype'];
$searchterm=$_REQUEST['searchterm'];
// cut out the whitespace
$searchterm= trim($searchterm);
// testing to see the user entered a search type and a search term
if (!$searchtype || !$searchterm)
{
echo 'Please enter search details. Please go back and try again';
exit;
}
// slashes out control characters
$searchtype= addslashes($searchtype);
$searchterm= addslashes($searchterm);
// make connection to database
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
@ $db = mysql_pconnect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
if (!$db)
{
echo 'Error: Could not connect to Database. Please Try Again';
exit;
}
$db=mysql_select_db('moviedatabase') or die("could not connect ".mysql_error);
$query = ("SELECT * FROM `actor` WHERE $searchtype LIKE '%$searchterm%'"$result = mysql_query($query);
$num_results = mysql_num_rows($result);
echo '<p>Number of Results found: '.$num_results.' </p>';
// loop to output number of results to the screen
for ($i=0; $i <$num_results; $i++)
{
// test to see that the search type is Actor/Actress
if ($searchtype == "Actor/Actress"
{
echo "<table border=1 >";
echo "<tr><td> Actor ID</td><td>Forename</td><td>Surname</td>><td>Age</td><td>Date of Birth</td><td>Nationality</td><td>Character Names</td><td>Photo</td></tr>";
while($row = mysql_fetch_array($result))
{ echo "<td>{$row[Actor_ID]}</td>";
echo "<td>{$row[Forename]}</td>";
echo "<td>{$row[Surname]}</td>";
echo "<td>{$row[Age]}</td>";
echo "<td>{$row[Date_of_Birth]}</td>";
echo "<td>{$row[Nationality]}</td>";
echo "<td>{$row[Character_Names]}</td>";
echo "<td>{$row[Photo]}</td></tr>";
}
echo "</table>";
//else ( echo 'No results Found: Please go back and try again')
}
}
?>
</body>
</html>
I keep getting this error:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\apps\phpmyadmin2.11.5\search.php on line 44
Number of Results found
I think my query is correct in terms of syntax and thats the only thing I thought could be the problem.
What im trying to do is read in the drop down menu searchtype and read in the search text box search term. E.g click on actor in the drop down menu and enter hugh grant in my text box
PLEASE HELP ME