0

I'm working on a php blog , i created a database and it has several fields,
i performed an sql command retrieving the id , performed a $query then a mysqli_fetch_array
on the $query i retrieved the id and stored it ina variable as follows `$pid=$row['id'];
so that the link would be set as www.somesite.com/index.php?pid=1 or pid =2
i attempted to GET the pid as follows

if(!_GET['pid']){ 
         //do something
     }else 
     $pageid= $_GET['pid'];

i keep getting this error ->"Undefined index: pid"
isn't the $_GET array an associative array, why can't i acess it??

3
Contributors
4
Replies
32
Views
3 Years
Discussion Span
Last Post by JorgeM
1

How about using isset?

 if(isset($_GET['pid'])) {
          $pageid= $_GET['pid'];
 }
1

Have you corrected the missing $ in line 1 of your code (as JorgeM suggested). You might have overlooked it since the error wasn't explicitly mentioned (just guessing).

Also you can examine the contents $_GET array by adding this code in the beginning of the script:

die(print_r($_GET, 1));
0

Have you corrected the missing $ in line 1 of your code (as JorgeM suggested)

Yes, I did intend to mention the missing "$" in my response, but forgot about it when I started writing the alternative code example..

This question has already been answered. 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.