Trouble with forms and PHP - Help please

Discussion in 'PHP' started by lateuk, Mar 21, 2007.

  1. #1
    Hello,
    Can someone explain why this does not work?

    <td><input name="Name" type="text" size="50" maxlength="80" value=<?php echo "Mr Smell";?>></td>

    but this does.

    <td><input name="Name" type="text" size="50" maxlength="80" value="Mr Smell"></td>

    The first one only populates the field with the text before the space, the second example populates it with the 2 words including the space?!?

    Thanks

    Late
     
    lateuk, Mar 21, 2007 IP
  2. Houdas

    Houdas Well-Known Member

    Messages:
    158
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #2
    If I see correctly, in the first code line you are missing the quotes around "value" attribute.
     
    Houdas, Mar 21, 2007 IP
  3. lateuk

    lateuk Active Member

    Messages:
    317
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    58
    #3
    Yes, but if i put the quotes in, it puts the <?php etc in the field as text.
     
    lateuk, Mar 21, 2007 IP
  4. Ekdal

    Ekdal Peon

    Messages:
    68
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Try this:

    <input name="Name" type="text" size="50" maxlength="80" value="<?php echo 'Mr Smell';?>">

    One question: Does your file ends with .php or .htm?
     
    Ekdal, Mar 21, 2007 IP
  5. lateuk

    lateuk Active Member

    Messages:
    317
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    58
    #5
    this works but i want to use a variable name:

    <input name="Name" type="text" size="50" maxlength="80" value="<?php echo '$myvar';?>">

    This justs prints the text $myvar in the field.

    Its a .php page, but it loads some HTML pages too.
     
    lateuk, Mar 21, 2007 IP
  6. Ekdal

    Ekdal Peon

    Messages:
    68
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Remove the single quotes, like this:

    <input name="Name" type="text" size="50" maxlength="80" value="<?php echo $myvar; ?>">

    It should work.
     
    Ekdal, Mar 21, 2007 IP
  7. lateuk

    lateuk Active Member

    Messages:
    317
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    58
    #7
    worked a treat. Many thanks.
     
    lateuk, Mar 22, 2007 IP
  8. wongjowo

    wongjowo Peon

    Messages:
    73
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I love this;
    <input name="Name" type="text" size="50" maxlength="80" value="<?= $myvar; ?>">
     
    wongjowo, Mar 23, 2007 IP
  9. jitesh

    jitesh Peon

    Messages:
    81
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #9
    <td><input name="Name" type="text" size="50" maxlength="80" value="<?php echo "Mr Smell";?>"></td>
     
    jitesh, Mar 23, 2007 IP