PDA

View Full Version : If statment with 3 times OR ..how to write it correctly?


jesica
06-18-2008, 06:26 AM
Hello everybody,

i would like to ask , how can i have correct my syntax when i want to use if statment with three times OR operator . See this example :

if(($_POST['fruit1'] > 0) OR ($_POST['fruit2'] > 0) OR ($_POST['fruit3'] > 0) {
$frut = TRUE;
}
else
{
$frut = FALSE;
echo '<b>Please choose at least 1 of 3 fruits</b>';
}

Is this the correct syntax when i want to use if and compare 3 times weith OR ? Cause when am testing my whole code am getting an error right on this point, something with my OR's and if statment aint correct . :(

Please can you help me ..?

Thanks a lotta n' waiting for your answers ;)

Inigoesdr
06-18-2008, 06:43 AM
You're missing a closing parenthesis at the end of the if() condition.

jesica
06-18-2008, 06:50 AM
Okay i fixed it but and am facing troubles, now the error am getting is the follow :

Parse error: syntax error, unexpected $end in E:\xamp\www\index.php on line 150

why ? 150 line is the end of my php document there that </html> ends :p why am getting this ?

if(($_POST['fruit1'] > 0) OR ($_POST['fruit2'] > 0) OR ($_POST['fruit3'] > 0)) {
$frut = TRUE;
}
else
{
$frut = FALSE;
echo '<b>Please choose at least 1 of 3 fruits</b>';
}

jesica
06-18-2008, 07:11 AM
ok fixed yo's it was just a bracket missing ;)
thanks a lotta :D

rafiki
06-18-2008, 01:32 PM
you could of used a switch statement?

xspy
06-19-2008, 11:33 AM
if ( ( empty ( $_POST[ 'fruit1' ] ) ) AND ( empty ( $_POST[ 'fruit2' ] ) ) AND ( empty ( $_POST[ 'fruit3' ] ) ) ) {

$fruit = FALSE ;

echo '<b>Please choose at least 1 of 3 fruits</b>' ;

}

else {

$fruit = TRUE ;

}

masterofollies
06-19-2008, 03:11 PM
Another way of writing it is this.


if($_POST['fruit1'] > 0) {
$frut = TRUE;
}

elseif ($_POST['fruit2'] > 0) {
$frut = TRUE;
}

elseif ($_POST['fruit3'] > 0) {
$frut = TRUE;
}

else
{
$frut = FALSE;
echo '<b>Please choose at least 1 of 3 fruits</b>';
}


Also for this problem

Parse error: syntax error, unexpected $end in E:\xamp\www\index.php on line 150

Your just missing a single closing bracket. } put it at the end of your script.