Jump to content

The "if" and "else...if" statements


Lineman

Recommended Posts

Being a right old n00b i have been practicing the "if" and "else...if" statements hoping to output the correct day of the week. Using the code bellow. Could someone take pity and tell me where i've gone wrong please. Thanks

 

When i have tried to run the code i received the following error message:

Parse error: syntax error, unexpected T_ELSE in /home/lineman/public_html/days.php on line 15

 

<html>
<body>

<?php

$today = Monday;

if ($today == Monday); {
print "Today is Monday";
}

else if ($today == Tuesday); {
print "Today is Tuesday";
}

else if ($today == Wednesday); {
print "Today is Wednesday";
}

else if ($today == Thursday); {
print "Today is Thursday";
}

else if ($today == Friday); {
print "Today is Friday";
}

else if ($today == Saturday); {
print "Today is Saturday";
}

else if ($today == Sunday); {
print "Today is Sunday":
}

else {
print"What day of the week is it then?";
}

?>

</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/100641-the-if-and-elseif-statements/
Share on other sites

remove semicolons

 

 

<?php

$today = Monday;

if ($today == Monday) {
print "Today is Monday";
}

else if ($today == Tuesday) {
print "Today is Tuesday";
}

else if ($today == Wednesday){
print "Today is Wednesday";
}

else if ($today == Thursday) {
print "Today is Thursday";
}

else if ($today == Friday) {
print "Today is Friday";
}

else if ($today == Saturday) {
print "Today is Saturday";
}

else if ($today == Sunday) {
print "Today is Sunday";
}

else {
print"What day of the week is it then?";
}

?>

Thanks for the help. I am now getting an output. The trouble is the output is Monday when today is actually Friday?

 

Think i may have overreached myself as it were and was being too ambitious trying to output the correct day.

Will try and learn a little more before making another attempt i think. Cheers folks!

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.