Skip to content
PHP Logo

How can PHP be integrated with HTML to create interactive and dynamic web pages for user input and output?

To integrate PHP with HTML for interactive and dynamic web pages, you can use PHP code within your HTML files to handle user input and generate dynamic content. PHP can process form data, interact with databases, and perform other server-side tasks to create a personalized user experience.

php
<!DOCTYPE html>
<html>
<head>
    <title>Interactive Web Page</title>
</head>
<body>
    <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
        <label for="name">Enter your name:</label>
        <input type="text" name="name">
        <input type="submit" value="Submit">
    </form>

    <?php
    if ($_SERVER["REQUEST_METHOD"] == "POST") {
        $name = $_POST['name'];
        echo "<p>Hello, $name! Welcome to our website.</p>";
    }
    ?>
</body>
</html>