Skip to content Skip to sidebar Skip to footer

Putting A Php Variable In A Html Form Value

I've got a php variable like so.. $name = $_REQUEST['name']; I'd like to put it in a HTML form field's value e.g in here..

Solution 1:

value="<?php echo htmlspecialchars($name); ?>"

Solution 2:

You can do it like this,

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

But seen as you've taken it straight from user input, you want to sanitize it first so that nothing nasty is put into the output of your page.

<input type="text" name="name" value="<?php echo htmlspecialchars($name);?>" />

Post a Comment for "Putting A Php Variable In A Html Form Value"