ok really stupid question

Discussion in 'PHP' started by whiteblue1942, Apr 12, 2008.

  1. #1
    but i cant figure it out for the life of me...how do i echo just like any piece of data from my table in my database

    like i want to echo one of the fields like some guys last name

    i already have the information in there i just dont know how to spit it out heres what im trying....

    $sql="SELECT * FROM users WHERE firstname='$_POST[firstname]' and pass='$_POST[pass]'";
    $result=mysql_query($sql);
    
    echo $_POST[lastname];
    Code (markup):
     
    whiteblue1942, Apr 12, 2008 IP
  2. MakeThatDollar

    MakeThatDollar Notable Member

    Messages:
    4,451
    Likes Received:
    158
    Best Answers:
    0
    Trophy Points:
    225
    #2
    Try echo '$result[lastname]';
     
    MakeThatDollar, Apr 12, 2008 IP
  3. jjacquay712

    jjacquay712 Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    i think you should put ' ' inside of the brackets like you would do in $_POST[' ']
     
    jjacquay712, Apr 12, 2008 IP
  4. Ikki

    Ikki Peon

    Messages:
    474
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hi there,

    This is what you need:

    
    $sql="SELECT * FROM users WHERE firstname='" . $_POST['firstname'] . "' and pass='" . $_POST['pass'] . "'";
    $result=mysql_query($sql);
    
    while($row=mysql_fetch_row($result)) {
      echo $row[0]; // "$row[0]" will show up the first field of your table, "$row[1]" the second field and so on
    }
    
    PHP:
    Hope that helps ;)

    P.S.: your code is highly insecure, mate. You need to clean your $_POST variables from any malicious code before using them to prevent a MySQL injection attack. PM me if you need to ask anything, ok? ;)
     
    Ikki, Apr 12, 2008 IP
  5. jakomo

    jakomo Well-Known Member

    Messages:
    4,262
    Likes Received:
    82
    Best Answers:
    0
    Trophy Points:
    138
    #5
    Hello,
    Another way is:

    Browse Information

    $sql ="Select yourfilename from table";
    $result= mysql_query($sql);
    while ($row = mysql_fetch_assoc($result))
    {
    echo $row['yourfilename'];
    }

    Best,
    Jakomo
     
    jakomo, Apr 13, 2008 IP