Quick PHP help needed

Discussion in 'PHP' started by technoguy, Mar 26, 2009.

  1. #1
    I have a problem that I have got data in variable like this

    $name="Test User";

    but when I keep this variable in echo its printing well but when I keep it in the textbox

    
    echo "<input type=text name=txtname value=".$name.">";
    
    PHP:
    then its only showing "Test" in the textfield it means it is displaying only one word

    can anyone help me?
     
    technoguy, Mar 26, 2009 IP
  2. hassanahmad1

    hassanahmad1 Active Member

    Messages:
    150
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Use this instead:
    
    echo "<input type=text name=txtname value=\"".$name."\">";
    
    Code (markup):
    You need to put quotes ("") around the value paramter also!
     
    hassanahmad1, Mar 26, 2009 IP
  3. javaongsan

    javaongsan Well-Known Member

    Messages:
    1,054
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #3
    echo '<input type=text name=txtname value=$name>';
     
    javaongsan, Mar 26, 2009 IP
  4. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #4
    Your syntax is wrong.

    ---------

    Either

    echo '<input type="text" name="txtname" value="'.$name.'" />';
    PHP:
    or

    echo "<input type=\"text\" name=\"txtname\" value=\"$name\" />";
    PHP:
    The first one is better.
     
    ads2help, Mar 27, 2009 IP
  5. kusal

    kusal Peon

    Messages:
    91
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You can do this also
    
    <input type="text" name="txtname" value="<?php echo $name; ?>" />
    Code (markup):
     
    kusal, Mar 27, 2009 IP