am trying to come up with a way to pull out information from a query string in php instead of having to use js (ick). is there any standard command i'm just totally missing as i search through the phb manual? i need to take a url and pull the query string (ex: www.yoursite.com/index.php?userid=1) and pull out the "userid=1" part of it. anybody know if i'm just totally stupid on this one? please, please tell me i don't have to use javascript for this.....i can do it, but i hate it.....looking for a totally php/xhtml solution for the site i'm working on.

    whoa. that link worked. i meant for it to be an example, not to actually link to some actual site. perhaps i should've said ex: "http://www.<domain>.com/<document>.php?query_string

    thanks again for any info i can get
    -pel

      $GET['var']
      $
      POST['var']

      check to see if it exists before using:
      if isset($_GET['username'])

      or

      if array_key_exists($_GET['username'])

      Is this what you are looking for?

      Kerry Kobashi
      Kobashi Computing

        so then $_Get[xxxxxx] will pull any data from the query sting and set it to the variable xxxxxx when i use this command? am i understanding this right? note: i'm still getting weirded out by how much more concise the syntax is with php over other languages. it always seems too easy when i look at correct code.

        thanks a bunch, dude.

          $GET is an array that contains all the variables sent by the GET or POST method. When you write $GET["xxxx"], you don't call a function, but you simply get the value (the content) of the variable.

          Is it clearer ?

            okay. so in theory if the query string was something like ?user=15 and i said $_GET["user"] , it could return 15?

              if i am right u want the value of userid from the link

              "www.yoursite.com/index.php?userid=1"

              u can just get the value using the variable $userid. simple

              u dont have to use $GET[].

                pelleas, not only can you get "15," you will get "15!" 😃

                That is exactly how it works.

                prithvi, you are correct with older versions of PHP, where register_globals defaults to "on" in the php.ini file. However, if register_globals is off (which is the default with 4.2.x and up), then you cannot use $userid, unless you set it yourself:

                $userid = $_GET["userid"]

                  rock. php is way easier that js. god. the idea that it's a one-line command is just ridiculous when coming from having used js before. php owns and then some. great language. thanks for all the help on this one, guys. i think i've been convinced that this is my new forum of choice 😉

                    okay. had no access to site all week, but am in again now. anybody know why this isn't working? my page is named www.yoursite.com/user_info.php?userid=1

                    <?php
                    //pulls user number from titlebar, sets to $user_id
                    $userid= $_GET["userid"];
                    printf("%s", $useridentifier); //tests to see if value is set -just for dev purposes-delete when done
                    //pull up all rows where user_id is the same as the value of userid
                    $result= mysql_query("SELECT * FROM user WHERE user_id='$userid'",$mysql_connect);
                    //for every row that is fetched
                    $row= mysql_fetch_array($result);
                    //prints the user's information fields
                    printf("<p class=\"headline\">User Information</p><em><b>User Name:</b></em><br />%s<br /><br />\n",
                    $row[1]);
                    ?>

                      Originally posted by prithvi
                      if i am right u want the value of userid from the link

                      "www.yoursite.com/index.php?userid=1"

                      u can just get the value using the variable $userid. simple

                      u dont have to use $GET[].

                      Wrong, because in the latest distributions of PHP, register_globals is off by default which automatically creates variables from the query string. Therefore it's deprecated and you have to use superglobals like $GET, $POST, etc.

                        Originally posted by pelleas
                        <?php
                        //pulls user number from titlebar, sets to $user_id
                        $userid= $_GET["userid"];
                        printf("%s", $useridentifier);
                        ...
                        ?> [/B]

                        You put the value of $_GET["userid"] in $userid and then, you print $useridentifier... doesn't make sense ! Why don't you print $userid ??

                          suppose that makes sense. logic and i are far from comrades 😉

                          but it still doesn't answer why i'm not getting anything out of the query string. have modified the code:

                          <?php
                          //pulls user number from titlebar, sets to $user_id
                          $userid= $_GET["userid"];
                          //pull up all rows where user_id is the same as the value of userid
                          $result= mysql_query("SELECT * FROM user WHERE user_id='$userid'",$mysql_connect);
                          //for every row that is fetched
                          $row= mysql_fetch_array($result);
                          //prints the user's information fields
                          printf("<p class=\"headline\">AlliedGames User Information</p><em>&nbsp;<br /><b>User Name:</b></em><br />%s<br /><br /><em><b>User Status:</b></em><br />%s<br /><br /><em><b>User Email:</b></em><br />%s<br /><br /><em><b>User ICQ:</b></em><br />%s<br /><br /><em><b>User Website:</b></em><br /><a href=\"%s\">%s</a><br /><br /><em><b>User Location:</b></em><br />%s<br /><br /><em><b>User Comments:</b></em><br />%s\n",
                          $row[1], $row[4], $row[5], $row[6], $row[7], $row[7], $row[8], $row[9]);
                          ?>

                          i know that the end of that looks nuts, but it's cuz i've only just set it up and gotten it working. the annoying part is that everything is working fine except for the actual get. i can't seem to pull any info out of the query string at all.

                          -pel

                            Write a Reply...