I'm doing a search between dates here.
I'm having trouble restricting the display of my records..
The problem i'm having here is when user selects the year of the endDate and sends the form..
all records were displayed which should not be the case
What it should have been is "Please enter a valid search.." even if the the year of endDate been selected

i tried adding the ($day =="") && ($month =="") but just couldnt get it working..

$month = isset($REQUEST['month1']) ? $REQUEST['month1'] : '';
$day = isset($REQUEST['day1']) ? $REQUEST['day1'] : '';

if(($AircraftType =="") && ($ServicingType == "") &&  ($AirFrameHours == "") && ($AirFrameHours2 == "") && ($Keyword == "") && ($endDate =="") && ($day =="") && ($month =="")) { 
   //set the result message display to Search Error Please enter a search if all values are empty 
   $resultmsg = " Please enter a valid search.." ; 
} 


$day = isset($_REQUEST['day']) ? $_REQUEST['day'] : ''; 
$month = isset($_REQUEST['month']) ? $_REQUEST['month'] : ''; 
$year = isset($_REQUEST['year']) ? $_REQUEST['year'] : ''; 

//$beingDate is set to empty space if the variables $day,$month and $year are empty 
$beginDate = ''; 
if(!empty($day) && !empty($month) && !empty($year)) { 
//include the dash if the variables $day,$month and $year are not empty 
   $beginDate = $year . '-' . $month . '-' . $day; 

} // end if 



$year = date("Y"); 
$selected_year = isset($_REQUEST['year1']) ? $_REQUEST['year1'] : ''; 
echo "<select name='year1'>\n"; 
echo "<option value='' >-</option>"; 
for ($n=$year;$year-10<=$n;$n--) { // gets the current year and do a subtraction of 10 to display the array of descending 10 years 
if($n==$selected_year){ 
echo " <option value=\"$n\" selected>$n</option>"; } 
else { echo " <option value=\"$n\">$n</option>"; } 
} // end for 
echo "</select>\n"; 


$day = isset($_REQUEST['day1']) ? $_REQUEST['day1'] : ''; 
$month = isset($_REQUEST['month1']) ? $_REQUEST['month1'] : ''; 
$year = isset($_REQUEST['year1']) ? $_REQUEST['year1'] : ''; 

/****************************************************** 
include the dash if the variables are not empty 

******************************************************/ 
$endDate = ''; 
if(!empty($day) && !empty($month) && !empty($year)) { 
   $endDate = $year . '-' . $month . '-' . $day; 
} // end if 

    Your long 'if' statement should be with '||' (OR) and not '&&' (AND). That's assuming that every HTML field is required (needs to be filled in). So, if one of them is not populated the error message will be invoked. Right now, all fields will have to be empty before the error message is set.

    if (($AircraftType =="") || ($ServicingType == "") || ...

    🙂

      Oh.. i'm working on a optional search.. so it is not required that all of the fields any to be filled in..

      Anyway thanks.. i got that figured out.. =)

        Write a Reply...