#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    33
    Rep Power
    1

    Angry PHP blog $_GET error


    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 `
    PHP Code:
    $pid=$row['id'
    ;
    so that the link would be set as index.php?pid=1 or pid =2
    i attempted to GET the pid as follows

    PHP Code:
    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??
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,070
    Rep Power
    9398
    Assuming that ! there is actually a !$ in your code,

    Because it's not there. If you try to access it and it's not there then PHP will issue a warning. If you're not sure if it's there then you should check with isset before you try to use it.
    PHP Code:
    if(!isset($_GET['pid'])) { 
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    33
    Rep Power
    1

    $_GET error


    I tried that @requinix and i'm still getting the same error
    Notice: Undefined index: pid , did i mention i'm hosting this blog on a local server, could that be why, the $_GET array isn't accessible that way?
  6. #4
  7. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,070
    Rep Power
    9398
    No, that's not it.

    You're still using $_GET["pid"] somewhere without first checking isset(). What's the rest of your code?
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    33
    Rep Power
    1
    Originally Posted by requinix
    Assuming that ! there is actually a !$ in your code,

    Because it's not there. If you try to access it and it's not there then PHP will issue a warning. If you're not sure if it's there then you should check with before you try to use it.
    PHP Code:
    if(!isset($_GET['pid'])) { 

    the php error displays the line that the error is on, and its the error i modified with the code you gave, however this is the code i'm using to select the id from mysql database

    PHP Code:
    $sqlCommand ="SELECT id, linklabel FROM pages WHERE showing ='1' ORDER BY id ASC";
    $query =mysqli_query($myConnection,$sqlCommand) or die(mysqli_error());

    $menuDisplay ='';
      while(
    $row mysqli_fetch_array($query)){
            
    $pid $row["id"]; 
    i'm in a class that teaches setting up a custom CMS.
  10. #6
  11. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    And at what point do you believe the variable $pid will be added as a GET parameter to a link to another page?
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    33
    Rep Power
    1
    Originally Posted by ManiacDan
    And at what point do you believe the variable $pid will be added as a GET parameter to a link to another page?
    @ManiacDan -> thats that i'm hoping for, its not working out.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    33
    Rep Power
    1
    Originally Posted by ManiacDan
    And at what point do you believe the variable $pid will be added as a GET parameter to a link to another page?
    accordinng to the class , i have rendered href links with custom pids or ids and the next next is to receive the content that correlates with the id's from the sql table when the links are clicked
  16. #9
  17. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    You need to show these bits. Show where you use $pid
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

IMN logo majestic logo threadwatch logo seochat tools logo