Page 1 of 1

echo Value in form field

Posted: Sun Jan 29, 2006 10:46 am
by ssand
Hi,
I need a little help. I have a form field that I want to echo the value.

Right now I have this code and it's not working.

Code: Select all

<?php echo "value=\"".$_POST['fn']."\""; ?>
I added an echo statement just outside the form field for $_POST['fn'] and the contents are displayed no problem.

EDIT:
I have also tried this varient as well and doesn't seem to work

Code: Select all

<?php echo "value=".$_POST['fn']; ?>
Thank you

Posted: Sun Jan 29, 2006 10:52 am
by raghavan20

Code: Select all

<input type = 'text' name = 'input_name' value = '<?php echo $_POST["value"]; ?>' />

Posted: Sun Jan 29, 2006 10:53 am
by feyd
more code would be helpful. What type of form element are we talking here?

Posted: Sun Jan 29, 2006 10:56 am
by ssand
sorry feyd

Code: Select all

<input type="text" name="fn" <?php echo "value=\"".$_POST['fn']."\""; ?> size="25">

Posted: Sun Jan 29, 2006 12:33 pm
by ssand
Well, it works as raghavan20 suggested.

Is it something with forms that the value= needed to be outside the php?

Thanks

Posted: Sun Jan 29, 2006 1:44 pm
by jayshields
No it's not. At a glance I can't really see what's wrong with your original code, but there are many alternatives to rag's method, none of which necessarily involve keeping the value attribute outside of the PHP.