Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9

Thread: php $_GET error

  1. #1
    New Coder
    Join Date
    Oct 2013
    Posts
    16
    Thanks
    2
    Thanked 1 Time in 1 Post

    Angry php $_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 in a 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
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,026
    Thanks
    23
    Thanked 588 Times in 587 Posts
    if(!$_GET['pid']){

    your missing the $
    Evolution - The non-random survival of random variants.

  • Users who have thanked sunfighter for this post:

    rhodoscoder (10-24-2013)

  • #3
    New Coder
    Join Date
    Oct 2013
    Posts
    16
    Thanks
    2
    Thanked 1 Time in 1 Post
    @sunfighter , i forgot to type the $ in here , i do actually have it in the code , i tried
    PHP Code:
    isset 
    according to advice given by other forums and still getting the same error

  • #4
    Regular Coder
    Join Date
    Nov 2011
    Posts
    250
    Thanks
    8
    Thanked 4 Times in 4 Posts
    Is the URL showing as index.php?pid=2 ?

  • #5
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,026
    Thanks
    23
    Thanked 588 Times in 587 Posts
    I think I could have answered this before, but you use index.php as your second site page and this is not possible. When a user goes to a site they will go to the page that is titled index.htm or index.html or index.php; which ever one there is. But only one of them.

    So let's say a user enters your site and logs in. You get their identification number from a sql query
    Code:
    $row["id"] = 2390; // gotten from the query
    $pid=$row['id'];     // setting variable $pid equal to the id or as we say $pid is equal to 2390.
    We then call the next page and pass that id to them. Like this in PHP:
    PHP Code:
    <?php
    $row
    ["id"] = 2390;
    $pid=$row['id'];
    header"location:page2.php?pid=$pid" ) ;
    ?>
    Please note that pid is the name we will look for in the $_GET variable and that we used double quotes so $pid would be read as 2390. If we used single quotes we would pass $pid, a string, to the $_GET variable.

    page2.php code:
    PHP Code:
    <?php
    $this_page_pid 
    $_GET["pid"];
    echo 
    $this_page_pid;    // so you see what was passed
    ?>
    Hope this helps
    Evolution - The non-random survival of random variants.

  • Users who have thanked sunfighter for this post:

    rhodoscoder (10-25-2013)

  • #6
    New Coder
    Join Date
    Oct 2013
    Posts
    16
    Thanks
    2
    Thanked 1 Time in 1 Post

    Smile

    Quote Originally Posted by sunfighter View Post
    I think I could have answered this before, but you use index.php as your second site page and this is not possible. When a user goes to a site they will go to the page that is titled index.htm or index.html or index.php; which ever one there is. But only one of them.

    So let's say a user enters your site and logs in. You get their identification number from a sql query
    Code:
    $row["id"] = 2390; // gotten from the query
    $pid=$row['id'];     // setting variable $pid equal to the id or as we say $pid is equal to 2390.
    We then call the next page and pass that id to them. Like this in PHP:
    PHP Code:
    <?php
    $row
    ["id"] = 2390;
    $pid=$row['id'];
    header"location:page2.php?pid=$pid" ) ;
    ?>
    Please note that pid is the name we will look for in the $_GET variable and that we used double quotes so $pid would be read as 2390. If we used single quotes we would pass $pid, a string, to the $_GET variable.

    page2.php code:
    PHP Code:
    <?php
    $this_page_pid 
    $_GET["pid"];
    echo 
    $this_page_pid;    // so you see what was passed
    ?>
    Hope this helps
    Thanks @ sunfighter, i noticed this in php mysql commands, it interprets ' ' and " " differently, i'm i getting this?

  • #7
    New Coder
    Join Date
    Oct 2013
    Posts
    16
    Thanks
    2
    Thanked 1 Time in 1 Post
    @sunfighter....dude it worked, thank you so much, I'm psyched up ...no more errors, proceeding on

  • #8
    New Coder
    Join Date
    Oct 2013
    Posts
    16
    Thanks
    2
    Thanked 1 Time in 1 Post
    The errors are gone , however the menu display rendered by obtaining the id value from the mysql database here
    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'];
            
    $linklabel $row["linklabel"];

            
    $menuDisplay .='<a href="index.php?pid=' $pid '">' $linklabel '</a><br />';
      
      }
    mysqli_free_result($query); 
    doesn't access the pages when clicked on , when i change the values manually in the web address it shows the content

  • #9
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,026
    Thanks
    23
    Thanked 588 Times in 587 Posts
    What happens if you use this instead?
    $menuDisplay .= "<a href='test_2.php?pid=$pid>$linklabel</a><br />";
    Evolution - The non-random survival of random variants.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •