| | |
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 32 Days Ago
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: 525
Reputation:
Solved Threads: 61
0
#4 32 Days Ago
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 32 Days Ago
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
- 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)
- Undefined index error (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 beginner beneath binary broadband broken button cakephp checkbox class cms code countingeverycharactersfromastring crack cron curl database date display dynamic echo email error fcc file files folder form forms freelancing function functions google href htaccess html image include incode insert integration ip javascript joomla limit link login mail match menu method mlm mod_rewrite multiple mysql oop pageing pagerank paypal pdf php problem query radio random recursion recursiveloop remote script search server sessions sms smtp soap source space sql strip_tags subversion support! survey syntax system table template tutorial undefined update upload url validator variable video virus web window.onbeforeunload=closeme; youtube





