0

I'm getting a Notice: Undefined index when I load my page at every of the following lines. The code works like expected only the source file (the html online) gives this notice. I'm new to php but I learned that a notice needs to be fixed if possible.

<select name='table'>
    <option value='table1' <?php if($_GET['table']=="Table1"){echo "SELECTED";}?> >page1</option>
    <option value='table2' <?php if($_GET['table']=="Table2"){echo "SELECTED";}?> >page2</option>
    <option value='table3' <?php if($_GET['table']=="Table3"){echo "SELECTED";}?> >page3</option>
    <option value='table4' <?php if($_GET['table']=="Table4"){echo "SELECTED";}?> >page4</option>
    <option value='table5' <?php if($_GET['table']=="Table5"){echo "SELECTED";}?> >page5</option>
</select>

I tried to add an isset if(isset($_get but that did not work. Is there a way to get rid of this notice?

user3602420
  • 127
  • 1
  • 11

1 Answers1

0

Use isset function to check if the key exists:

<?php if(isset($_GET['table']) && $_GET['table'] =="Table1"){echo "SELECTED";}?>

You mention you tried to use isset, so im guessing you got your syntax wrong

Steve
  • 20,703
  • 5
  • 41
  • 67
  • thank you. this worked. Your guess was correct. I used it the wrong way. I thought I needed isset so i tried `` and i tried ``. i couldn't find the answer on this site or on the internet so thank you. – user3602420 Jun 13 '14 at 15:09