Jump to content

If else help


peter11

Recommended Posts

I have tried it like this,

 

<?php
if($points==0 && $answer=="me"){
setcookie("points", "1", time()+3600);
$points ++;
echo "CORRECT";
}
if($points == 0 && $answer !="me"){
echo "Incorrect - Please try again";
}
?>

 

however when i enter "me" it runs both of these saying CORRECTIncorrect - Please tr again

how can it be True and False?

 

Whats wrong with this statement. [/code]

Link to comment
https://forums.phpfreaks.com/topic/210448-if-else-help/#findComment-1098150
Share on other sites

<?php
if($points==0 && $answer=="me"){
setcookie("points", "1", time()+3600);
$points ++;
echo "CORRECT";
}

if($points==1 && $answer=="reading"){
setcookie("points", "2", time()+3600);
$points ++;
echo "CORRECT";
}

if($points==2 && $answer=="q2"){
setcookie("points", "3", time()+3600);
$points ++;
echo "CORRECT";
}


if($points==0 && $answer !="me"){
echo "Incorrect - Please try again";
}
if($points==1 && $answer !="reading"){
echo "Incorrect - Please try again";
}
if($points==2 && $answer !="q2"){
echo "Incorrect - Please try again";
}
?>

 

If you enter it incorrectly it says incorrect however if you enter "me" correctly it says correct and incorrect if you enter "reading" correctly it says correct and incorrect however if you enter "q2" correctly it just says correct. Anyone know why this is?

Link to comment
https://forums.phpfreaks.com/topic/210448-if-else-help/#findComment-1098174
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.