Varri
Varri

Reputation: 19

Undefined Variable when using $_GET even though the url string has variable in it

Edit: The issue ended up being because I was trying to resubmit to the same page. See Jeromes solution on here if you're experiencing the same issue.

if( isset( $_GET["fil"]) ){
    print "hi";
    $test = $_GET["fil"];
    print $test;
}
?>
<form action='prob1handlerFilter.php' method='GET'>
<h1>Filter These Results</h1>
  <select name='fil' id='fil'>
    <?php
    $SCORE = $_SESSION["players"]; 
    $uniqueDates = array_values(array_unique($_SESSION["players"]));
    sort($uniqueDates);
    $x = 0;
        while($x < count($uniqueDates))
        {
            print "<option value = '$uniqueDates[$x]'> $uniqueDates[$x]          </option>";
            $x = $x + 1;
        }
    ?>

Above is my code. The issue is that even though I can see in the URL string that fil is for sure set(http://127.0.0.1:8080/webserver1/prob1/prob1handlerFilter.php?fil=2012), it is telling me that it is undefined. If I change the if statement to !isset, it will go through and print "hi", but nothing else. This is just confusing me because I can literally see the variable in the URL string and all my other forms are working, just not this one....I'm at a complete loss as to why it's telling me that it's undefined. Full error is

Notice: Undefined index: fil in C:\xampp\htdocs\webserver1\prob1\prob1handler.php on line 70.

But clearly it isn't undefined because it's sitting up in the URL string...

Upvotes: 0

Views: 222

Answers (1)

jerome
jerome

Reputation: 715

Can you try changing the form action value to

 "<?php echo $_SERVER['PHP_SELF'];?>"

Upvotes: 1

Related Questions