search engine help
Posted: Fri Jan 05, 2007 11:53 am
i have a small search form with a few fields (one of them is required). i'm having trouble figuring out how to make it work. for instance, if there is an input field that doesn't have data, how would i populate a MySQL query to not query that field? i've got two text input fields (one of which is required) and 3 drop down menus. here's my code.
here's my query so far... which barely works...
i don't know what to do. or even where to start... any suggestions? it is posting to the same page, btw.
Code: Select all
<form method="POST" action="index.php?action=simplesearch">
First Name:<input type="text" name="fname"><BR>
Last Name:<input type="text" name="lname"><FONT COLOR="FF0000" SIZE="-1">(required)</FONT><BR>
<TABLE><TR>
<TD>
<SELECT NAME="event_month">
<OPTION VALUE="">select a month
<OPTION VALUE="1">January
<OPTION VALUE="2">February
<OPTION VALUE="3">March
<OPTION VALUE="4">April
<OPTION VALUE="5">May
<OPTION VALUE="6">June
<OPTION VALUE="7">July
<OPTION VALUE="8">August
<OPTION VALUE="9">September
<OPTION VALUE="10">October
<OPTION VALUE="11">November
<OPTION VALUE="12">December
</SELECT>
</TD>
<TD>
<SELECT NAME="event_day">
<OPTION VALUE="">select a day
<OPTION VALUE="1">01
<OPTION VALUE="2">02
<OPTION VALUE="3">03
<OPTION VALUE="4">04
<OPTION VALUE="5">05
<OPTION VALUE="6">06
<OPTION VALUE="7">07
<OPTION VALUE="8">08
<OPTION VALUE="9">09
<OPTION VALUE="10">10
<OPTION VALUE="11">11
<OPTION VALUE="12">12
<OPTION VALUE="13">13
<OPTION VALUE="14">14
<OPTION VALUE="15">15
<OPTION VALUE="16">16
<OPTION VALUE="17">17
<OPTION VALUE="18">18
<OPTION VALUE="19">19
<OPTION VALUE="20">20
<OPTION VALUE="21">21
<OPTION VALUE="22">22
<OPTION VALUE="23">23
<OPTION VALUE="24">24
<OPTION VALUE="25">25
<OPTION VALUE="26">26
<OPTION VALUE="27">27
<OPTION VALUE="28">28
<OPTION VALUE="29">29
<OPTION VALUE="30">30
<OPTION VALUE="31">31
</SELECT>
</TD>
<TD>
<SELECT NAME="event_year">
<OPTION VALUE="">select a year
<OPTION VALUE="2002">2002
<OPTION VALUE="2003">2003
<OPTION VALUE="2004">2004
<OPTION VALUE="2005">2005
<OPTION VALUE="2006">2006
<OPTION VALUE="2007">2007
<OPTION VALUE="2008">2008
<OPTION VALUE="2009">2009
<OPTION VALUE="2010">2010
</SELECT>
</TD>
</TR>
</TABLE>
<CENTER>
<input type="SUBMIT" value="Search">
<?php
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$event_day = $_POST['event_day'];
$event_month = $_POST['event_month'];
$event_year = $_POST['event_year'];
?>
</CENTER>
</form>Code: Select all
$result = mysql_query("SELECT * FROM my_search_table
WHERE brideLname LIKE '%". $lname ."%' OR groomLname LIKE '%". $lname ."%'
AND event_month ='". $event_month ."'
AND event_day = '". $event_day ."'
AND event_year = '". $event_year ."'")
or die(mysql_error());