Trapping Undefined Indicies

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • IWP506@gmail.com

    Trapping Undefined Indicies

    Hey, here's some code:

    switch ($_GET["content"]) {
    case "1":
    include("./1_content.html" );
    break;
    case "2":
    include("./2_content.html" );
    break;
    default:
    echo("nothing!" );
    }

    That works perfectly... But what can I do about having the page not
    show undefined index errors if they don't insert ?content= at the end
    of the address?

    Thanks,
    iwp506@gmail.co m

  • Jerry Stuckle

    #2
    Re: Trapping Undefined Indicies

    IWP506@gmail.co m wrote:[color=blue]
    > Hey, here's some code:
    >
    > switch ($_GET["content"]) {
    > case "1":
    > include("./1_content.html" );
    > break;
    > case "2":
    > include("./2_content.html" );
    > break;
    > default:
    > echo("nothing!" );
    > }
    >
    > That works perfectly... But what can I do about having the page not
    > show undefined index errors if they don't insert ?content= at the end
    > of the address?
    >
    > Thanks,
    > iwp506@gmail.co m
    >[/color]

    if (isset($_GET['content']))
    switch.....
    else .....

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • Dave

      #3
      Re: Trapping Undefined Indicies

      (IWP506@gmail.c om) decided we needed to hear...[color=blue]
      > Hey, here's some code:
      >
      > switch ($_GET["content"]) {
      > case "1":
      > include("./1_content.html" );
      > break;
      > case "2":
      > include("./2_content.html" );
      > break;
      > default:
      > echo("nothing!" );
      > }
      >
      > That works perfectly... But what can I do about having the page not
      > show undefined index errors if they don't insert ?content= at the end
      > of the address?
      >
      > Thanks,
      > iwp506@gmail.co m[/color]

      use the isset() function to test if $_GET['content'] is set
      before you do your switch statement. See
      Determine if a variable is declared and is different than null


      --
      Dave <dave@REMOVEbun dook.com>
      (Remove REMOVE for email address)

      Comment

      • IWP506@gmail.com

        #4
        Re: Trapping Undefined Indicies

        You guys are the greastest...

        Comment

        • Janwillem Borleffs

          #5
          Re: Trapping Undefined Indicies

          IWP506@gmail.co m wrote:[color=blue]
          > Hey, here's some code:
          >
          > switch ($_GET["content"]) {
          > case "1":
          > include("./1_content.html" );
          > break;
          > case "2":
          > include("./2_content.html" );
          > break;
          > default:
          > echo("nothing!" );
          > }
          >[/color]

          You don't even have to use switch:

          if (isset($_GET['content']) &&
          file_exists("./{$_GET['content']}_content.html" )) {
          include "./{$_GET['content']}_content.html" ;
          } else {
          print 'Nothing!';
          }


          JW



          Comment

          Working...