Learn PHP Programming

A backend server scripting language, and a powerful tool for making dynamic and interactive Web pages. Learn each topic with examples and output.

PHP Introduction
Control Structures
Php Forms
Php Advanced

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:

    <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 :

=