Hi
I want to query a database with the user having the option to enter their own search text or choose from a drop down list.
Firstly they have to choose to search by Company or Product.
I find that if I use the same ‘name’ for both the field and the list then it wont work.
This is the code I have so far
<?php
// create short variable names
$searchtype=$HTTP_POST_VARS['searchtype'];
$searchterm=$HTTP_POST_VARS['searchterm'];
$searchterm= trim($searchterm);
if (!$searchtype || !$searchterm)
{
echo ' <p class="style45"><span class="body12V">Please enter your search details.';
exit;
}
$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);
@ $db = mysql_pconnect('localhost', '****', '****');
if (!$db)
{
echo 'Error: Could not connect to database. Please try again later.';
exit;
}
mysql_select_db('*****');
$result = mysql_query("SELECT * FROM sttasources",$db);
$query = "select * from sttasources where ".$searchtype." like '%".$searchterm."%'";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
echo '<p class="style45"><span class="body12V">Number of Members found: '.$num_results.'</span></p>';
searchtype is the choice between Company or Product in a drop down.
searchterm is the name for both the field and the list.
How do I change this code to do what I want.
This is the page in question
http://www.stta.org.uk/testsite/membersearch.php
Which brings me to my second problem with the page.
Because of the code:
if (!$searchtype || !$searchterm)
{
echo ' <p class="style45"><span class="body12V">Please enter your search details.';
exit;
}
The page doesn’t load completely - how do I sort this.
Please be gentle coz my php skills are limited.
Thanks
David
dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options