Results 1 to 7 of 7

Thread: The $_GET variable

  1. #1
    Join Date
    May 2009
    Posts
    5

    Default The $_GET variable

    I am trying to get values from firstpage.php and send them to secondpage.php this is what i have figured out and i am wondering if it is the correct way to do it thanks.

    Firstpage.php

    PHP Code:
     <?php
    //Connects to the database.
    $con mysql_connect("localhost","blank","blank") or die (mysql_error());
    $db mysql_select_db("wsdatabase") or die (mysql_error());
    // Selects username's from the user table.
    $sql "select username from users";
    $query mysql_query($sql);
    // List's every name in the table with a link going to the secondpage.php.
    while($row mysql_fetch_array($query)) {
        
    printf("<a href='secondpage.php?username=%s'>%s</a>"."<br/>",$row['username'],$row['username']);
    }
    ?>
    secondpage.php

    PHP Code:
     <?php
    // Grabs the username with the get method.
    if(isset($_GET['username'])) {
        
    $username $_GET['username'];
    }
    // Connects to the database.
    $con mysql_connect("localhost","blank","blank") or die (mysql_error());
    $db mysql_select_db("wsdatabase") or die (mysql_error());
    // Selects everything from the database.
    $sql "select * from users where username = '$username' ";
    $query mysql_query($sql);
    // Prints everything out from the database.
    while($row mysql_fetch_array($query)) {
        echo 
    "<b>".$row['title']."</b>";
        echo 
    "<br/>";
        echo 
    "<b>".$row['username']."</b>";
        echo 
    "<br/>";
        echo 
    "<b>".$row['email']."</b>";
    }
    ?>

  2. #2
    Join Date
    Jun 2009
    Posts
    6

    Default

    I think it work ok, but in my opinion this is not really a good way.
    If i were you, I will use POST method to avoid posting variable to address
    Btw, you should print some thing when there is no username match $_GET['username'], kind da like: User name ABC not found or st :)

  3. #3
    Join Date
    Sep 2009
    Posts
    4

    Default

    what is '%s' ?

  4. #4
    Join Date
    Nov 2009
    Posts
    7

    Default

    Quote Originally Posted by topsitex View Post
    what is '%s' ?
    joining the question .

  5. #5
    Join Date
    Feb 2010
    Posts
    6

    Default

    yes what is '%s' ;

  6. #6
    Join Date
    Jan 2008
    Posts
    2

    Default

    No i dont thinks so...
    %s?! you mine:
    printf("<a href='secondpage.php?username="".$row['username'].""'>".$row['username']."</a>"."<br/>");

    get the info by _POST

  7. #7
    Join Date
    Jul 2011
    Posts
    5

    Default

    i love PHP:grin::grin::grin: its lots of fun and really cool.

Bookmarks

Posting Permissions

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