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.. <input type="text" name="name" value=(php variable here) />
How would I do so?
Thanks.
PHP code cannot be nested within itself. echo "<? php echo 'foo' ?>" is going to print PHP code, not "foo". and even then, you're using the wrong type of quotes to allow embedding variables in text anyways.
In order to get an input value, you can use the htmlspecialchars() method and $_REQUEST variable. Note: The htmlspecialchars() method functions by converting special characters to HTML entities. The $_REQUEST variable is a built-in PHP variable that functions by getting data from the input field.
js"></script> </head> <body> <script type="text/javascript"> $. post('test. php',{'data': "value1"}); </script> <? php $data = $_POST['data']; print( "data is: $data" ); ?>
value="<?php echo htmlspecialchars($name); ?>"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With