text input value from database

Discussion in 'PHP' started by mcdeere02, Aug 5, 2009.

Thread Status:
Not open for further replies.
  1. #1
    I'm trying to get a persons full name into a text input box when they wish to edit their name. Something like this


    $sql = "SELECT * FROM users WHERE user_id='$_COOKIE[userid]'";
    $result = mysql_query($sql) or die(mysql_error());
    $data = mysql_fetch_array($result, MYSQL_ASSOC);

    echo '<input type="text" name="fullname" value='."$data[full_name]".'>';

    The problem is, it only displays the first word in the name. I tried using str_replace to replace the spaces with other characters like %20, +, and &nbsp, but it just literally echos those characters rather than the desired effect. Does anyone know a work around? Any help would be appreciated. Thanks
     
    mcdeere02, Aug 5, 2009 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    try fetch_assoc!
     
    EricBruggema, Aug 5, 2009 IP
  3. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Are you sure it's saved correctly in the DB?

    Also, you should really do it like this:

    
    $sql = "SELECT * FROM users WHERE user_id='" . mysql_real_escape_string($_COOKIE[userid]) . "'";
    $result = mysql_query($sql) or die(mysql_error());
    $data = mysql_fetch_array($result, MYSQL_ASSOC);
    
    echo '<input type="text" name="fullname" value="' . htmlspecialchars($data[full_name]) . '">';
    PHP:
     
    premiumscripts, Aug 5, 2009 IP
Thread Status:
Not open for further replies.