Continual "undefined index:day" errors in PHP script

Reply

Join Date: Nov 2008
Posts: 54
Reputation: whitestream6 is an unknown quantity at this point 
Solved Threads: 0
whitestream6 whitestream6 is offline Offline
Junior Poster in Training

Continual "undefined index:day" errors in PHP script

 
0
  #1
Oct 29th, 2009
This is my script, which is intended to show a different page depending on day of the week.

  1. <html>
  2. <? error_reporting(E_ALL);?>
  3. <body>
  4. <?
  5. $i=$_GET['day'];
  6.  
  7. switch ($i) {
  8. case 0:
  9. include("2.php");
  10. break;
  11. case 1:
  12. include("3.php");
  13. break;
  14. case 2:
  15. include("4.php");
  16. break;
  17. case 7:
  18. include("5.php");
  19. break;
  20. default:
  21. echo "page not found!!!!";
  22. }
  23. ?>
  24. <?php
  25. $d=date("D");
  26. switch ($d)
  27. {
  28. case "Mon":
  29. include("2.php");
  30. //echo "Today is Monday";
  31. break;
  32. case "Tue":
  33. include("3.php");
  34. //echo "Today is Tuesday";
  35. break;
  36. case "Wed":
  37. include("4.php");
  38. //echo "Today is Wednesday";
  39. break;
  40. case "Thu":
  41. include("5.php");
  42. //echo "Today is Thursday";
  43. break;
  44. case "Fri":
  45. include("6.php");
  46. //echo "Today is Friday";
  47. break;
  48. case "Sat":
  49. include("7.php");
  50. //echo "Today is Saturday";
  51. break;
  52. case "Sun":
  53. include("1.php");
  54. //echo "Today is Sunday";
  55. break;
  56. default:
  57. //echo "Wonder which day is this ?";
  58. }
  59. ?>

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
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 844
Reputation: pritaeas will become famous soon enough pritaeas will become famous soon enough 
Solved Threads: 137
Sponsor
pritaeas's Avatar
pritaeas pritaeas is offline Offline
Practically a Posting Shark
 
0
  #2
Oct 29th, 2009
$i=$_GET['day']; will cause the notice if you call the page without this parameter. To remove the notice, do this: $i = isset($GET['day']) ? $_GET['day'] : -1;
"If it is NOT source, it is NOT software."
-- NASA
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 54
Reputation: whitestream6 is an unknown quantity at this point 
Solved Threads: 0
whitestream6 whitestream6 is offline Offline
Junior Poster in Training
 
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

  1. <html>
  2. <body>
  3. <?
  4. $i = isset($GET['day']) ? $_GET['day'] : -1;
  5.  
  6. switch ($i) {
  7. case 0:
  8. include("2.php");
  9. break;
  10. case 1:
  11. include("3.php");
  12. break;
  13. case 2:
  14. include("4.php");
  15. break;
  16. case 7:
  17. include("5.php");
  18. break;
  19. default:
  20. echo "page not found!!!!";
  21. }
  22. ?>
  23. <?php
  24. $d=date("D");
  25. switch ($d): }
  26. case "Mon":
  27. include("2.php");
  28. //echo "Today is Monday";
  29. break;
  30. case "Tue":
  31. include("3.php");
  32. //echo "Today is Tuesday";
  33. break;
  34. case "Wed":
  35. include("4.php");
  36. //echo "Today is Wednesday";
  37. break;
  38. case "Thu":
  39. include("5.php");
  40. //echo "Today is Thursday";
  41. break;
  42. case "Fri":
  43. include("6.php");
  44. //echo "Today is Friday";
  45. break;
  46. case "Sat":
  47. include("7.php");
  48. //echo "Today is Saturday";
  49. break;
  50. case "Sun":
  51. include("1.php");
  52. //echo "Today is Sunday";
  53. break;
  54. default:
  55. //echo "Wonder which day is this ?";
  56. }
  57. ?>
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 527
Reputation: network18 is an unknown quantity at this point 
Solved Threads: 61
network18 network18 is offline Offline
Posting Pro
 
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 54
Reputation: whitestream6 is an unknown quantity at this point 
Solved Threads: 0
whitestream6 whitestream6 is offline Offline
Junior Poster in Training
 
0
  #5
Oct 29th, 2009
Now I'm getting this error message:
Parse error: syntax error, unexpected $end in C:\www\vhosts\mywebsite1\dayweek.php on line 58
My code now:
  1. <html>
  2. <body>
  3. <html>
  4. <body>
  5. <?
  6. $i = isset($GET['day']) ? $_GET['day'] : -1;
  7.  
  8. switch ($i) {
  9. case 0:
  10. include("2.php");
  11. break;
  12. case 1:
  13. include("3.php");
  14. break;
  15. case 2:
  16. include("4.php");
  17. break;
  18. case 7:
  19. include("5.php");
  20. break;
  21. default:
  22. echo "page not found!!!!";
  23. }
  24. ?>
  25. <?php
  26. $d=date("D");
  27. switch ($d) {
  28. case "Mon":
  29. include("2.php");
  30. //echo "Today is Monday";
  31. break;
  32. case "Tue":
  33. include("3.php");
  34. //echo "Today is Tuesday";
  35. break;
  36. case "Wed":
  37. include("4.php");
  38. //echo "Today is Wednesday";
  39. break;
  40. case "Thu":
  41. include("5.php");
  42. //echo "Today is Thursday";
  43. break;
  44. case "Fri":
  45. include("6.php");
  46. //echo "Today is Friday";
  47. break;
  48. case "Sat":
  49. include("7.php");
  50. //echo "Today is Saturday";
  51. break;
  52. case "Sun":
  53. include("1.php");
  54. //echo "Today is Sunday";
  55. break;
  56. default:
  57. //echo "Wonder which day is this ?"; }
  58. ?>
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 844
Reputation: pritaeas will become famous soon enough pritaeas will become famous soon enough 
Solved Threads: 137
Sponsor
pritaeas's Avatar
pritaeas pritaeas is offline Offline
Practically a Posting Shark
 
0
  #6
Oct 29th, 2009
the closing brace in line 57 is commented out, put it on the next line.
"If it is NOT source, it is NOT software."
-- NASA
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC