| | |
Continual "undefined index:day" errors in PHP script
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Nov 2008
Posts: 54
Reputation:
Solved Threads: 0
This is my script, which is intended to show a different page depending on day of the week.
When I run it, it partially works, but this notice appears at the top of the browser:
Notice: Undefined index: day in C:\www\vhosts\mywebsite1\dayweek.php on line 5
I would appreciate any advice anyone has on fixing this, since I always get the undefined index error, which makes the site not function properly.
Thanks
PHP Syntax (Toggle Plain Text)
<html> <? error_reporting(E_ALL);?> <body> <? $i=$_GET['day']; switch ($i) { case 0: include("2.php"); break; case 1: include("3.php"); break; case 2: include("4.php"); break; case 7: include("5.php"); break; default: echo "page not found!!!!"; } ?> <?php $d=date("D"); switch ($d) { case "Mon": include("2.php"); //echo "Today is Monday"; break; case "Tue": include("3.php"); //echo "Today is Tuesday"; break; case "Wed": include("4.php"); //echo "Today is Wednesday"; break; case "Thu": include("5.php"); //echo "Today is Thursday"; break; case "Fri": include("6.php"); //echo "Today is Friday"; break; case "Sat": include("7.php"); //echo "Today is Saturday"; break; case "Sun": include("1.php"); //echo "Today is Sunday"; break; default: //echo "Wonder which day is this ?"; } ?>
When I run it, it partially works, but this notice appears at the top of the browser:
Notice: Undefined index: day in C:\www\vhosts\mywebsite1\dayweek.php on line 5
I would appreciate any advice anyone has on fixing this, since I always get the undefined index error, which makes the site not function properly.
Thanks
•
•
Join Date: Nov 2008
Posts: 54
Reputation:
Solved Threads: 0
0
#3 Oct 29th, 2009
I get this error now in my code:
Parse error: syntax error, unexpected '}', expecting T_ENDSWITCH or T_CASE or T_DEFAULT in C:\www\vhosts\mywebsite1\dayweek.php on line 25
Parse error: syntax error, unexpected '}', expecting T_ENDSWITCH or T_CASE or T_DEFAULT in C:\www\vhosts\mywebsite1\dayweek.php on line 25
PHP Syntax (Toggle Plain Text)
<html> <body> <? $i = isset($GET['day']) ? $_GET['day'] : -1; switch ($i) { case 0: include("2.php"); break; case 1: include("3.php"); break; case 2: include("4.php"); break; case 7: include("5.php"); break; default: echo "page not found!!!!"; } ?> <?php $d=date("D"); switch ($d): } case "Mon": include("2.php"); //echo "Today is Monday"; break; case "Tue": include("3.php"); //echo "Today is Tuesday"; break; case "Wed": include("4.php"); //echo "Today is Wednesday"; break; case "Thu": include("5.php"); //echo "Today is Thursday"; break; case "Fri": include("6.php"); //echo "Today is Friday"; break; case "Sat": include("7.php"); //echo "Today is Saturday"; break; case "Sun": include("1.php"); //echo "Today is Sunday"; break; default: //echo "Wonder which day is this ?"; } ?>
•
•
Join Date: Sep 2009
Posts: 527
Reputation:
Solved Threads: 61
0
#4 Oct 29th, 2009
the switch should have '{' opening brace and not the closing brace '}' . that's why there's that syntax error.
"The discipline of writing something down is the first step towards making it happen."
follow me on twitter
follow me on twitter
•
•
Join Date: Nov 2008
Posts: 54
Reputation:
Solved Threads: 0
0
#5 Oct 29th, 2009
Now I'm getting this error message:
My code now:
•
•
•
•
Parse error: syntax error, unexpected $end in C:\www\vhosts\mywebsite1\dayweek.php on line 58
PHP Syntax (Toggle Plain Text)
<html> <body> <html> <body> <? $i = isset($GET['day']) ? $_GET['day'] : -1; switch ($i) { case 0: include("2.php"); break; case 1: include("3.php"); break; case 2: include("4.php"); break; case 7: include("5.php"); break; default: echo "page not found!!!!"; } ?> <?php $d=date("D"); switch ($d) { case "Mon": include("2.php"); //echo "Today is Monday"; break; case "Tue": include("3.php"); //echo "Today is Tuesday"; break; case "Wed": include("4.php"); //echo "Today is Wednesday"; break; case "Thu": include("5.php"); //echo "Today is Thursday"; break; case "Fri": include("6.php"); //echo "Today is Friday"; break; case "Sat": include("7.php"); //echo "Today is Saturday"; break; case "Sun": include("1.php"); //echo "Today is Sunday"; break; default: //echo "Wonder which day is this ?"; } ?>
![]() |
Similar Threads
- Undefined index error (PHP)
- Error: "Use of undefined constant" Help! (PHP)
- Undefined index (PHP)
- undefined index problem .. pls help asap (PHP)
- Undefined Index issue (MySQL)
- undefined index ['action'] (PHP)
- The mysterious errors of PHP (PHP)
- question about connecting odbc to sql through php script (PHP)
- Please school me in PHP script installation. (MySQL)
Other Threads in the PHP Forum
- Previous Thread: catch server port in apache
- Next Thread: Simple, One-Time PHP Load Balancing Using Random Redirects
| Thread Tools | Search this Thread |
apache api array back basic beginner binary broken cakephp checkbox class cms code computing confirm cron curl customizableitems database date delete display dynamic echo email error external file files filter folder form forms forum function functions gc_maxlifetime google headmethod host href htaccess html iframe image include insert ip javascript joomla limit link login mail malfunction memmory memory menu mlm multiple mysql navigation oop parsing paypal pdf php problem query question radio random recursion regex remote script search server sessions sms snippet soap source space sql syntax system table thesishelp trouble tutorial update upload url validator variable video web xml youtube





