php search

hi i am trying to make search for items in my database but its not wokring, here is the cod ehtat i have so far

Media-O RAMA Catalog Search <body

Media-O RAMA Catalog Search

<?php // create short variable names $searchtype=$HTTP_POST_VARS['searchtype']; $searchterm=$HTTP_POST_VARS['searchterm']; $searchterm= trim($searchterm) ;

if (!$searchtype || !$searchterm)
{
echo ‘You have not entered search details. Please go back and try again’;
exit;
}

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

@ $db = mysql_pconnect(‘localhost’,‘bookorama’,‘bookarama123’);

if (!$db)
{
echo ‘Error: Could not connect to database. Please go back and try again’;
exit;
}

mysql_select_db(‘booksr’);
$query = “select * from booksr where “.$searchtype.” like '%”.$searchterm."%’";
$result = mysql_query($query);

$num_results = mysql_num_rows_($result);

echo ‘

Number of books found: ‘.$num_result.’

’;

for ($i=0; $i <$num_results; $i++);
{
$row = mysql_fetch_array($result);
echo ‘

’. ($i+1).’.Title; ';
echo htmlspecialchars(stripslashes($row[‘title’]));
echo '

Author: ';
echo stripslashes($row[‘author’]);
echo '
ISBN: ';
echo stripslashes($row[‘ISBN’]);
echo '
Price: ';
echo stripslashes($row[‘price’]);
echo ‘

’;
}
?>

it keeps givng me this error code
Media-O RAMA Catalog Search
Notice: Undefined variable: HTTP_POST_VARS in G:\webclient\xampp\htdocs\web\results.php on line 10

Notice: Undefined variable: HTTP_POST_VARS in G:\webclient\xampp\htdocs\web\results.php on line 11
You have not entered search details. Please go back and try again

any help would be much appreciated

HTTP_POST_VARS[deprecated]

try to use:
[php]
$_POST[‘searchtype’]
$_POST[‘searchterm’]
[/php]

Hi Kim,

I think your form uses POST method so basically you should just use $_POST when requesting both for [‘searchtype’] and [‘searchterm’].

So, your $searchtype and $searchterm should now be:
[php]
$searchtype=$_POST[‘searchtype’];
$searchterm=$_POST[‘searchterm’];
//query…
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service