Insert PHP into HTML input tags and textarea

24th December 2018 posted in PHP

Beginner’s PHP tutorial

One of the first tasks you’ll encounter when starting up with PHP, is how to get PHP values into HTML text inputs, the PHP may come from the database for example.

Here is how to insert PHP into a simple HTML input element. First make sure the file extension is .php, then all you have to do is use opening and closing PHP tags and use echo to output the PHP as below.

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

Here is how you would enter PHP into a textarea

<textarea name="address"><?php echo $address; ?></textarea>

And that’s it! Any questions please leave a comment!

Tags: PHP