I’m desperate for a solution to a problem I have been experiencing for a while now.
[B][U]Background:
I have created a relatively simple four field form. The visitor has the option whether to choose one or all four of the fields. The form has a search process. It searches a MySQL database against:
– field 1 (name – if chosen),– field 2 (location – if chosen)
and fields 3 & 4 (date to and date from – if chosen)
N.B: Date to and Date from are populated from a javascript pop up calender. I can not immediately see if this is adding to the problem or not.
[B][U]Problem:
If the visitor is forced to choose all three options then the search process works fine and displays the correct results.
If the visitor is able to pick and choose fields, the search results – although display results – does not display results according to the choices made.
[B][U]Scripts:
The search form has the following fields and names:
Name = nm3
Location = County
Start Date = start
End Date = to
The PHP search script is as follows:
[CODE]if (!$_POST[‘start’]) {
$start = ‘1900-01-01’ ;
} else {
$start = $_POST[‘start’] ;
}
if (!$_POST[‘to’]) {
$to = ‘2050-01-01’ ;
} else {
$to = $_POST[‘to’] ;
}
if ((!$_POST[‘nm3’]) && (!$_POST[‘County’])) {
$result = mysql_query(“select * from table WHERE date BETWEEN ‘$start’ and ‘$to’ “) or die(mysql_error());
} else if (!$_POST[‘nm3’]) {
$result = mysql_query(“select * from table WHERE county='{$_POST[‘County’]}’ and date BETWEEN ‘$start’ and ‘$to’ “) or die(mysql_error());
} else if (!$_POST[‘County’]) {
$result = mysql_query(“select * from table WHERE name='{$_POST[‘nm3’]}” and date BETWEEN ‘$start’ and ‘$to’ “) or die(mysql_error());
} else {
$result = mysql_query(“select * from table WHERE name=’$nm3′ and county=’$County’ and date BETWEEN ‘$start’ and ‘$to’ “) or die(mysql_error());
}
$result1 = mysql_num_rows($result);
Any questions please feel free to ask….
Thanks,
CC