I am noticing some weird behavior in my script, not sure why its occurring though.
if ($date != 'NOW()' || $date != 'NULL')
{
// throw error
} else {
// run functions
}
I have a IF statement similar to the above in one of my functions, i pass the value 'NULL' from my function which it is receiving fine. But when doing the comparison with the IF statement, it doesn't work. Its always skipping to else statement.
UPDATE:
Below is the complete code for my function, i hope it helps.
public function setLastLoginDate( $date )
{
if (isset($date) && !empty($date))
{
if ($date != 'NOW()' || $date != 'NULL' || is_datetime(convertDateTimeToSql($date)) == false)
{
$this->errors['user_last_login'] = 'invalid date specified.';
} else {
this->properties['user_last_login'] = $date;
}
}
}
LAST UPDATE
Using && does work instead of ||, but i never intended to use &&.
if thats the way it is suppose to be then i guess i have to reRead about that.
Isn't && to check if two variables return true?
like if (is_string($foo) && strlen($foo) > 1) ?
but i want to check if the variable contains either of the values
But this also does the trick for me:
if ( $date == 'NOW()' || $date == 'NULL' || is_datetime(convertDateTimeToSql($date)) == true )
{
$this->properties['user_last_login'] = $date;
} else {
$this->errors['user_last_login'] = 'invalid date specified.';
}
Did some testing and its working as i want it to with the above. Is there something wrong using it as above?
Thanks
'NOW()', i pass this value from my script when i know it is needed. What it should do is assign the variable the value'NOW()'i later run a prepare function, when it assigns a value for the db fielddateit sends the mysql function'NOW()'to it.