simple if question....
<?php if ($where <1 && $who <1 && $date <1 $city <1 ) echo opps; }
If $where, $who, $date, $city does not have a value then I don't want to proceed, i got the else statement up fine, the if statement isnt working though...parse error...
Try...
if( !$where && !$who && !$date && !$city ) echo 'oops';
stupid !'s, i was doing that but forgot the !'s!
you mean
if( !$where <1 && !$who <1 && !$date <1 && !$city <1 )
right?
Originally posted by intenz Try... if( !$where && !$who && !$date && !$city ) echo 'oops'; [/B]
Originally posted by intenz Try...
[/B]
$where, $who $date $city MUST have a value and be equal to something. What you posted does not implement anything to allow for this extra requirement..
Huh? What do you mean?
its a submission form....the user must fill in the form and then the $variables must have values.
if $where does not have a value, then they will get the fail statement for the if...
if ($where <1){ echo fail; }
(the above does not work however when I try the below, it does...
[code=php] if ($where =1){ echo fail; }
[/code]
This works too
if (!$where){ echo fail; }
to check if each one has a value you need to use || (or)
if( !$where || !$who || !$date || !$city ) { echo 'oops'; }
I read somewhere that using the ! operator is coding. I don't know why though 🙂
empty($var) || empty($var2) etc is apparently a better practice. I guess it's down to personal preference again though.
you for got the last doubler apprisand in your code don't use the !$var pointed to earlier it's bad coding form
Originally posted by Shrike I read somewhere that using the ! operator is coding. I don't know why though 🙂
Duh, missed the word 'bad' 😉
Then try...
if( $where == '' && $who == '' && $date == '' && $city == '' ) echo 'oops';
Originally posted by Shrike I read somewhere that using the ! operator is coding. I don't know why though
Originally posted by Shrike
I read somewhere that using the ! operator is coding. I don't know why though
Anyone know why empty is better than !? I read something about it being more secure in the manual coments but it wasn't clear why.
This will not echo anything if $date has a value and the other three are blank. You need to use || instead of && to make sure all four have values.
Correct, BUT he didn't give a precise description of what he wanted. So it's not hard to misunderstand him.