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??

How about using isset?

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

@JorgeM tried , receiving the same error

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

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..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.