newguyneedshelp Posted July 1, 2013 Share Posted July 1, 2013 Can someone please help me with my code. It will not execute. <html><head><title>Favorite Original Six Hockey Team</title></head><body><h1>Original Six </h1><?php$t=date("H");if ($t<"10"){echo "Good morning!";}else if ($t<"20"){echo "Good afternoon!";}else{echo "Good evening!";}?> <br> <br><?php$favhockeyteam="blackhawks";switch ($favhockeyteam){case "blackhawks":echo "Your favorite hockey team is blackhawks!";break;case "redwings":echo "Your favorite hockey team is redwings!";break;case "bruins":echo "Your favorite hockey team is bruins!";break;case "canadians":echo "Your favorite hockey team is canadians!";break;case "maple leafs":echo "Your favorite hockey team is maple leafs!";break;case "rangers":echo "Your favorite hockey team is rangers!";break;default:echo "Your favorite color is neither red, blue, or green!";}?> <br> <br></body></html> Quote Link to comment https://forums.phpfreaks.com/topic/279741-need-help-with-my-code-it-will-not-execute/ Share on other sites More sharing options...
chriscloyd Posted July 1, 2013 Share Posted July 1, 2013 What are you trying to do? Quote Link to comment https://forums.phpfreaks.com/topic/279741-need-help-with-my-code-it-will-not-execute/#findComment-1438740 Share on other sites More sharing options...
newguyneedshelp Posted July 1, 2013 Author Share Posted July 1, 2013 Trying to execute a If_else and Switch statement on the same page. I want it to execute by the time of day and my favorite Team. Quote Link to comment https://forums.phpfreaks.com/topic/279741-need-help-with-my-code-it-will-not-execute/#findComment-1438741 Share on other sites More sharing options...
newguyneedshelp Posted July 1, 2013 Author Share Posted July 1, 2013 I am very new to php and i am having lots of trouble trying to figure this out. Quote Link to comment https://forums.phpfreaks.com/topic/279741-need-help-with-my-code-it-will-not-execute/#findComment-1438742 Share on other sites More sharing options...
chriscloyd Posted July 1, 2013 Share Posted July 1, 2013 (edited) Seems to be working fine for me... http://codetut.com/projects/switch.php I am guessing you are trying to pass in a variable so it switches cases? if so I added some code for you you can try it like this http://codetut.com/projects/switch.php?team=redwings here is the code now <html> <head> <title>Favorite Original Six Hockey Team</title> </head> <body> <h1>Original Six </h1> <?php $t = date("H"); if ($t < "10") { echo "Good morning!"; } else if ($t<"20") { echo "Good afternoon!"; } else { echo "Good evening!"; } ?> <br> <br> <?php $favhockeyteam = isset($_GET['team']) ? $_GET['team'] : ""; switch ($favhockeyteam) { case "blackhawks": echo "Your favorite hockey team is blackhawks!"; break; case "redwings": echo "Your favorite hockey team is redwings!"; break; case "bruins": echo "Your favorite hockey team is bruins!"; break; case "canadians": echo "Your favorite hockey team is canadians!"; break; case "maple leafs": echo "Your favorite hockey team is maple leafs!"; break; case "rangers": echo "Your favorite hockey team is rangers!"; break; default: echo "Your favorite color is neither red, blue, or green!"; } ?> <br> <br> </body> </html> Edited July 1, 2013 by chriscloyd Quote Link to comment https://forums.phpfreaks.com/topic/279741-need-help-with-my-code-it-will-not-execute/#findComment-1438743 Share on other sites More sharing options...
newguyneedshelp Posted July 1, 2013 Author Share Posted July 1, 2013 Thank You, I am not sure what the issue is but it is not executing in the environment i am working in. Thanks for the help, I really appreciate everything. Quote Link to comment https://forums.phpfreaks.com/topic/279741-need-help-with-my-code-it-will-not-execute/#findComment-1438745 Share on other sites More sharing options...
chriscloyd Posted July 1, 2013 Share Posted July 1, 2013 No problem, if you ever need hosting let me know when my site is done. I will be offering free hosting to people trying to learn how to code. Quote Link to comment https://forums.phpfreaks.com/topic/279741-need-help-with-my-code-it-will-not-execute/#findComment-1438746 Share on other sites More sharing options...
jcbones Posted July 1, 2013 Share Posted July 1, 2013 Are you trying to execute the file using a server, or just a file on your computer? Quote Link to comment https://forums.phpfreaks.com/topic/279741-need-help-with-my-code-it-will-not-execute/#findComment-1438749 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.