Can any of the gurus out there please help?
I am having a search problem with PHP and MySQL.
I wish to search the MySql database from 2 criteria.
Using 2 dropdown boxes.
I wish to search from 1 dropdown box called searchtype and another called searchterm. The problem is I cannot get them to work do a proper search.
I can get it to work using just one search criteria but I want the result to be of both criteria being true.
This is the form code for the search:
Search:
20002001200220032004
12345
This is the code for the results page:
<?php
// create short variable names
if(ini_get('register_globals') != "1")
{
$post = (floatval(substr(phpversion(), 0, 3)) >= 4.1) ? $_POST : $HTTP_POST_VARS;
foreach($post as $key => $value)
{
$$key = $value;
}
}
$searchtype = addslashes(trim($searchtype));
$searchterm = addslashes(trim($searchterm));
if(!$searchtype || !$searchterm)
{
exit('You have not entered search details. Please go back and try again.');
}
$link_id = @mysql_connect("localhost", "root", "password");
if($link_id === false)
{
exit("Error, Could not connect to the system database. Sorry...");
}
mysql_select_db('charts50', $link_id);
$result = mysql_query("SELECT * FROM `usa` WHERE `{$searchtype}` LIKE '%{$searchterm}` LIKE %'");
?>
50 YEARS AGO
TW
LW
Wks
Title
Artist
<?php $i = 1; while($row = mysql_fetch_array($result)){
$item = array();
$item['tw'] = stripslashes($row['tw']);
$item['lw'] = stripslashes($row['lw']);
// now we can override that
$item['lw'] = ($item['lw']=='new')
? "
"
: $item['lw'];
$item['wks'] = stripslashes($row['wks']);
$item['title'] = strtoupper(stripslashes($row['title']));
$item['artist'] = stripslashes($row['artist']);
?>
<?php echo $item['tw']; ?>
<?php echo $item['lw']; ?>
<?php echo $item['wks']; ?>
<?php echo $item['title']; ?>
<?php echo $item['artist']; ?>
<?php $i++; } ?>
I want the results to be true of both searchtype and searchterm.
If someone could please help by amending the correct code or tell me what I should amend on either the search form or the results code or both. That is true to year and wk no.
I have put 'password' just for this post.
All help is very much appreciated.