I’m trying to have the user input a day and then output the schedule based on the day they entered. However, no matter which day I put enter, it always outputs the schedule for Sunday. I feel like the code is relatively simple, yet I can’t figure where things went wrong.
<?php
if(isset($_GET['day']) && $_GET["day"] != ""){
$day = $_GET['day'];
echo $day;
echo'success';
}
$error = "Please select a day of week";
if ($day = "Monday" || $day = "monday"){
$sched = "<br> Go shopping for Nobita's mom and get some dorayaki on the way <br> Eat dorayaki while reading manga";
}
if ($day = "Tuesday" || $day = "tuesday"){
$sched = "<br> Go on a date with Mii-chan <br> Help Nobita with his problems <br> Play ball with Nobita and his friends";
}
if ($day = "Wednesday" || $day = "wednesday"){
$sched = "<br> Continue the manga from Monday <br> Go to run errands for Nobita's mom";
}
if ($day = "Thursday" || $day = "thursday"){
$sched = "Fly around town with the takecopter <br> Hears Nobita crying <br> Pulls Nobita out of the hole he fell into";
}
if ($day = "Friday" || $day = "friday"){
$sched = "<br> Buy new gadgets<br> Continue reading the manga <br>Get some broken gadgets fixed";
}
if ($day = "Saturday" || $day = "saturday"){
$sched = "<br> Go out for some dorayaki <br> Call Dorami";
}
if ($day = "Sunday" || $day = "sunday"){
$sched = "<br> Goes out with Nobita for baseball<br> Get icecream <br> Go to Suneo's house for dinner";
}
else {
$error;
}
?>
<html>
<head>
<title>Doraemon's Schedule for the Week</title>
</head>
<body>
<?php
if($day =="monday" || $day == "Monday" || $day == "tuesday" || $day == "Tuesday" || $day == "thursday" || $day == "Thursday" || $day == "friday" || $day == "Friday" || $day == "saturday" || $day == "Saturday" || $day == "sunday" || $day == "Sunday"|| $day == "wednesday" || $day == "Wednesday"){
echo "Today's schedule: " . $sched;
}else {
echo $error;
}
?>
</body>
</html>
When I echo the day at the top, it shows exactly the day I entered, but the corresponding schedule is not outputed.
New contributor
Cindy Jiang is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.