Skip to content
PHP Logo

What are the key PHP functions used to process form data and display results on the same page?

When processing form data and displaying results on the same page in PHP, you can use the isset() function to check if the form has been submitted, and then use $_POST or $_GET superglobals to retrieve the form data. You can then perform any necessary processing, validation, or calculations before displaying the results back on the same page using echo or print statements.

php
<?php
if(isset($_POST['submit'])){
    $name = $_POST['name'];
    $email = $_POST['email'];
    
    // Perform any processing or validation here
    
    echo "Thank you for submitting your information, $name. Your email is $email.";
}
?>

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <input type="text" name="name" placeholder="Name">
    <input type="email" name="email" placeholder="Email">
    <button type="submit" name="submit">Submit</button>
</form>