PHP Form Handling
Form handling in PHP is a common way to collect user data and process it. Forms are created in HTML and can use two primary methods to submit data to a server-side script: the GET and POST methods. These methods differ in how they transmit data and how the server-side script accesses it:
GET Method:
POST Method:
    <html>
<head>
    <title>Simple Form</title>
</head>
<body>
    <h2>Simple Form Example</h2>
    <form method="post" action="">
        <label for="username">Username:</label>
        <input type="text" id="username" name="username" required><br><br>
        <label for="password">Password:</label>
        <input type="password" id="password" name="password" required><br><br>
        <input type="submit" value="Submit">
    </form>
    <?php
    if ($_SERVER["REQUEST_METHOD"] == "POST") {
        $username = $_POST["username"];
        $password = $_POST["password"];
        echo "<h3>Submitted Data:</h3>";
        echo "Username: $username<br>";
        echo "Password: $password";
    }
    ?>
</body>
</html>
Output :
In next chapter we start learning php form Validation
Share this page on :
© 2022 AnalyzeCode.com All rights reserved.