Logic problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
PhpDog
Forum Commoner
Posts: 58
Joined: Mon Jan 14, 2008 10:23 am

Logic problem

Post by PhpDog »

I have created a function, validDate(), which validates dates. It returns 0 if the format is OK and the date is valid.
I need to check two textfields for possible user date input. Such input is only meaningful if they have first selected a date field, from a select list, to search from which is called $dates.

So I have:

Code: Select all

 
if((validDate($dateFrom) == 0) || (validDate($dateTo) == 0) && ($dates == "Please select a date field to search on"))
{
    $errors = 1;
 $table .= 
     "
      <table width='100%'  border='0' cellpadding='1'>
                  <tr>
                        <td class='warning'><div align='center'>ERROR! - Please select a date field to search on</div></td>
                  </tr>
               </table> 
     ";
     
}
 
but it is not operating as expected right now. Can anyone please see where my logic is at fault?

If either of the date validations returns zero and $dates == "Please select a date field to search on" then generate the html error message.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Logic problem

Post by Christopher »

You probably want:

Code: Select all

if( ( (validDate($dateFrom) == 0) || (validDate($dateTo) == 0) ) && ($dates == "Please select a date field to search on"))
Also, wouldn't it make more sense for validDate() to return true if valid and false if not? Or rename it invalidDate().
(#10850)
PhpDog
Forum Commoner
Posts: 58
Joined: Mon Jan 14, 2008 10:23 am

Re: Logic problem

Post by PhpDog »

arborint wrote:You probably want:

Code: Select all

if( ( (validDate($dateFrom) == 0) || (validDate($dateTo) == 0) ) && ($dates == "Please select a date field to search on"))
Also, wouldn't it make more sense for validDate() to return true if valid and false if not? Or rename it invalidDate().
In the cold light of today - yes! When I orignally wrote it, somehow if made perfect sense. :lol: Oh ,dear ....
Post Reply