0

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

<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

3
Contributors
5
Replies
8
Views
7 Years
Discussion Span
Last Post by pritaeas
0

$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;

0

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

<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 ?"; 
}
?>
0

the switch should have '{' opening brace and not the closing brace '}' . that's why there's that syntax error.

0

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:

<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 ?"; }
?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.