Jump to content

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!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.