944,033 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 590
  • PHP RSS
Oct 29th, 2009
0

Continual "undefined index:day" errors in PHP script

Expand Post »
This is my script, which is intended to show a different page depending on day of the week.

PHP Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 15
Solved Threads: 0
Junior Poster
whitestream6 is offline Offline
169 posts
since Nov 2008
Oct 29th, 2009
0
Re: Continual "undefined index:day" errors in PHP script
$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;
Sponsor
Featured Poster
Reputation Points: 556
Solved Threads: 731
Bite my shiny metal ass!
pritaeas is offline Offline
4,192 posts
since Jul 2006
Oct 29th, 2009
0
Re: Continual "undefined index:day" errors in PHP script
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

PHP Syntax (Toggle Plain Text)
  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. ?>
Reputation Points: 15
Solved Threads: 0
Junior Poster
whitestream6 is offline Offline
169 posts
since Nov 2008
Oct 29th, 2009
0
Re: Continual "undefined index:day" errors in PHP script
the switch should have '{' opening brace and not the closing brace '}' . that's why there's that syntax error.
Reputation Points: 29
Solved Threads: 76
Practically a Master Poster
network18 is offline Offline
616 posts
since Sep 2009
Oct 29th, 2009
0
Re: Continual "undefined index:day" errors in PHP script
Now I'm getting this error message:
Quote ...
Parse error: syntax error, unexpected $end in C:\www\vhosts\mywebsite1\dayweek.php on line 58
My code now:
PHP Syntax (Toggle Plain Text)
  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. ?>
Reputation Points: 15
Solved Threads: 0
Junior Poster
whitestream6 is offline Offline
169 posts
since Nov 2008
Oct 29th, 2009
0
Re: Continual "undefined index:day" errors in PHP script
the closing brace in line 57 is commented out, put it on the next line.
Sponsor
Featured Poster
Reputation Points: 556
Solved Threads: 731
Bite my shiny metal ass!
pritaeas is offline Offline
4,192 posts
since Jul 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: catch server port in apache
Next Thread in PHP Forum Timeline: Simple, One-Time PHP Load Balancing Using Random Redirects





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC