3

I have a function allowing members to update their personal details when they have logged in, the update page features a form the user will fill in and when the submit button is pressed the deatils are updated. This works fine, I am wanting to display the users current details in the appropriate text filed in the form e.g. the firstname text field will have value "James" and the user can delete this to enter "jim". Is it something to do with adding a value to the form field? My form is shown below.

    <tr>
    <td width="78">Firstname</td>
    <td width="6">:</td>
    <td width="294"><input name="firstname" type="text" id="firstname"></td>
    </tr>
    <tr>
    <td width="78">Surname</td>
    <td width="6">:</td>
    <td width="294"><input name="surname" type="text" id="surname"></td>
    </tr>

Any help is much appreciated

1
  • Three table cells to do what a label/input can do. Awesome. Commented May 8, 2012 at 17:10

2 Answers 2

1

Print value inside the text box.

<input type="text" value="<?php echo $someValue; ?>" />

Sign up to request clarification or add additional context in comments.

3 Comments

@josh i din see your answer before i post.. :(
Thans will i have to declare the variable $firstname like this? $firstname= $row["firstname"];
@user1368371 plz accept answer if its useful. Yes you can get value to a variable or you can print it directly inside the value with echo.
1

echo '<input type="text" value="'. $someValue .'" />';

OR

<input type="text" value="<?php echo $someValue; ?>" />

Both obviously require that you be in a .php file, and that $someValue contains the appropriate value to set. Watch out for the double quotes around the value, too. Without them, any spaces will break the value when it's rendered.

4 Comments

Your answer is great, could you please add <?= $someValue ?> as third option. I found it perfectly suitable for cases like this one
@Kyborek: I didn't include that example, because short tags are now deprecated: cubicspot.blogspot.com/2009/06/…
Oh i missed that one, you got a point and thanks for the info.
@Josh As of 5.4, <?= always works regardless of the short tags directive.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.