Select * from table_name WHERE userid='.....'

Discussion in 'PHP' started by Kyriakos, Apr 15, 2008.

  1. #1
    hi guys,

    i have done the records selection from mysql db but now i want to view the details for each record. this is my php code:
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <?php
    $userid = $_GET["userid"];
    ?>
    </head>
    <body>
    <?php
    $con = mysql_connect("localhost","root","");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    mysql_select_db("storedb", $con);
    
    $result = mysql_query("SELECT * FROM dealers
    WHERE userid='$userid;'");
    
    while($row = mysql_fetch_array($result))
      { ?>
    <?php echo $row['company']; ?><br /><?php echo $row['vat']; ?>
    <?php
    }
    ?>
    </body>
    </html>
    
    PHP:
    when i type manualy a "userid" in this section:
    the record details are appearing correct. what i can do to play dynamically?

    thanks in advance.
     
    Kyriakos, Apr 15, 2008 IP
  2. CreativeClans

    CreativeClans Peon

    Messages:
    128
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You need a form with an input field for the userid.
    Then in your PHP script you use $_POST['userid'] or $_GET['userid'] (depends on the form method) to retrieve the value inserted by the user.
     
    CreativeClans, Apr 15, 2008 IP
  3. ksamir2004

    ksamir2004 Peon

    Messages:
    70
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    your sql statement is wrong so i am making it right.. just paste it place of $result.

    $result = mysql_query("SELECT * FROM dealers WHERE userid=' ".$userid." ' ");

    Sure this will work..

    Thanks
    Sam
     
    ksamir2004, Apr 15, 2008 IP
  4. it career

    it career Notable Member

    Messages:
    3,562
    Likes Received:
    155
    Best Answers:
    0
    Trophy Points:
    270
    #4
    what happens if you do not specify userid ( I mean userid="") , also do not use root as userid to connect to mysql server.
     
    it career, Apr 15, 2008 IP
  5. Xtrm2Matt

    Xtrm2Matt Active Member

    Messages:
    129
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    58
    #5
    As said, you need a form:

    
    <?php
    if( $_POST )
    {
        $con = mysql_connect( "localhost", "root", "" );
    
        if ( !$con )
        {
            die( "Could not connect: ". mysql_error( ) );
        }
    
        mysql_select_db( "storedb", $con );
    
        $userid= $_POST["userid"];
        $fetch = mysql_query( "SELECT * FROM dealers WHERE userid='".$userid."'" );
        
        while( $array = mysql_fetch_array( $fetch ) )
        {
            echo "".$row["company"]."<br />".$row["vat"]."";
        }
    }
    ?>
    
    <form method="post" action="">
    User ID: <input type="text" name="userid" />
    <input type="submit" value="Submit" />
    </form>
    
    PHP:
     
    Xtrm2Matt, Apr 15, 2008 IP
  6. Kyriakos

    Kyriakos Active Member

    Messages:
    155
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #6
    now it's displaying this error message:
    line 21 is this:
     
    Kyriakos, Apr 15, 2008 IP
  7. Kyriakos

    Kyriakos Active Member

    Messages:
    155
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #7
    my fault. it's working now. thank you man.
     
    Kyriakos, Apr 15, 2008 IP
  8. Kyriakos

    Kyriakos Active Member

    Messages:
    155
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #8
    the form was created before this page my friend.

    how i can change the username and password of mysql database? can you tell me?
     
    Kyriakos, Apr 15, 2008 IP