Page 1 of 1

Help

Posted: Thu Apr 15, 2004 6:00 pm
by idnoble
Hello,
I wrote a lilttle script to search a database and each time I search i always get this error message

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in d:\phpweb\search.php on line 23

I've gone through the script over and over again but no success, can someone please help me

the script is below

Code: Select all

<?php
//Create short variable names
$search = $HTTP_POST_VARS['search'];
$search= trim($search);
if (!$search)
{
echo '<p style= "font-size: 15pt"><strong>You have not specified a search term. Please go back and try again.</strong></p>';
exit;
}
$search = addslashes($search);
$session = mysql_connect('localhost', 'root', 'platinum');
if (!$session)
{
echo 'Error: Could not connect to database. Please try again later.';
exit;
}

mysql_select_db('xplosive')or die(mysql_error());
$query = "select * 
from movies, music
where Title like '%".$search."%'";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);

echo '<p style= "font-size: 15pt"><strong>Number of products found: '.$num_results.'</strong></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 />Genre: ';
 echo stripslashes($row['Genre']);
 echo '<br/> Synopsis: ';
 echo stripslashes ($row['Synopsis']);
 echo'<br> Price: ';
 echo stripslashes ($row['Price']);
 echo '<br/> Itemcode: ';
 echo stripslashes ($row['Price']);
 echo '</p>';
}
?>

Posted: Thu Apr 15, 2004 6:02 pm
by tim
$result = mysql_query($query);

change

$result = mysql_query($query) or die(mysql_error());

let us know what that tells ya

Posted: Thu Apr 15, 2004 6:18 pm
by idnoble
thank you, i've done that and now the error message has changed to

Column: 'Title' in where clause is ambiguous

any ideas?

thank you

Posted: Thu Apr 15, 2004 6:20 pm
by markl999
Both the music and movies tables have a Tiltes column, so it doesn't know which one you are refering to in the query.
So you want something like:
$query = "select *
from movies, music
where movies.Title like '%".$search."%' OR music.Title like '%".$search."%'";