开发者

putting a php variable in a HTML form value

开发者 https://www.devze.com 2023-01-08 07:53 出处:网络
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..开发者_JS百科 <input type=\"text\" name=\"name\" value=(php variable h

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..开发者_JS百科 <input type="text" name="name" value=(php variable here) /> How would I do so?

Thanks.


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


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);?>" />
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号