Skip to content
PHP Logo

How can a PHP script return a value to be displayed in a specific location in an HTML form after submission?

To return a value to be displayed in a specific location in an HTML form after submission, you can use PHP to process the form data, store the value in a variable, and then echo the variable in the desired location within the HTML form. This can be achieved by using a conditional statement to check if the form has been submitted, retrieving the form data using $_POST or $_GET, and then displaying the value in the appropriate location within the HTML form.

php
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $value = $_POST['input_name'];
    echo '<div>'.$value.'</div>';
}
?>

<form method="post" action="">
    <input type="text" name="input_name">
    <button type="submit">Submit</button>
</form>