Lineman Posted April 11, 2008 Share Posted April 11, 2008 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> Quote Link to comment https://forums.phpfreaks.com/topic/100641-the-if-and-elseif-statements/ Share on other sites More sharing options...
zenag Posted April 11, 2008 Share Posted April 11, 2008 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?"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/100641-the-if-and-elseif-statements/#findComment-514696 Share on other sites More sharing options...
Daniel0 Posted April 11, 2008 Share Posted April 11, 2008 Change print "Today is Sunday": to print "Today is Sunday"; (semi-colon instead of colon). It'll also have to be e.g. 'Sunday' instead of Sunday. Quote Link to comment https://forums.phpfreaks.com/topic/100641-the-if-and-elseif-statements/#findComment-514697 Share on other sites More sharing options...
Lineman Posted April 11, 2008 Author Share Posted April 11, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/100641-the-if-and-elseif-statements/#findComment-514711 Share on other sites More sharing options...
Daniel0 Posted April 11, 2008 Share Posted April 11, 2008 Did you add either single or double quotes around the strings? If you did, then the code should work as expected. Quote Link to comment https://forums.phpfreaks.com/topic/100641-the-if-and-elseif-statements/#findComment-514716 Share on other sites More sharing options...
conker87 Posted April 11, 2008 Share Posted April 11, 2008 Well, you're setting $today as a constant: 'Monday' it wont change according to the day of the week. Quote Link to comment https://forums.phpfreaks.com/topic/100641-the-if-and-elseif-statements/#findComment-514720 Share on other sites More sharing options...
Lineman Posted April 11, 2008 Author Share Posted April 11, 2008 Shall just have to learn all i can and then attempt another project like this. Thanks for all the replies. Quote Link to comment https://forums.phpfreaks.com/topic/100641-the-if-and-elseif-statements/#findComment-514880 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.