Monday, October 12, 2020

PHP Form Handling

Hello dear readers! welcome back to another edition of my tutorial on PHP. In this tutorial guide, we will be studying about the PHP Form Handling.

What is a Dynamic Website?

A dynamic website can be defined as a website that provides the functionalities that can be used to store, update, retrieve, and delete the data in a database.

What is a Form?

A form is simply a document that contains blank fields, that the user can fill the data or user can select the data. Generally the data will be stored in the database.


The below example shows how a form can be used to perform some specific actions by using the post method -

      <title>PHP Form Validation</title>
         // define variables and set to empty values
         $name = $email = $gender = $comment = $website = "";
         if ($_SERVER["REQUEST_METHOD"] == "POST") {
            $name = test_input($_POST["name"]);
            $email = test_input($_POST["email"]);
            $website = test_input($_POST["website"]);
            $comment = test_input($_POST["comment"]);
            $gender = test_input($_POST["gender"]);
         function test_input($data) {
            $data = trim($data);
            $data = stripslashes($data);
            $data = htmlspecialchars($data);
            return $data;
      <h2>Web Design Tutorialz course registration form</h2>
      <form method = "post" action = "/php/php_form_introduction.htm">
               <td><input type = "text" name = "name"></td>
               <td><input type = "text" name = "email"></td>
               <td>Specific Time:</td>
               <td><input type = "text" name = "website"></td>
               <td>Class details:</td>
               <td><textarea name = "comment" rows = "5" cols = "40"></textarea></td>
                  <input type = "radio" name = "gender" value = "female">Female
                  <input type = "radio" name = "gender" value = "male">Male
                  <input type = "submit" name = "submit" value = "Submit"> 
         echo "<h2>Your Given details are as :</h2>";
         echo $name;
         echo "<br>";
         echo $email;
         echo "<br>";
         echo $website;
         echo "<br>";
         echo $comment;
         echo "<br>";
         echo $gender;


When the above code is executed, it will produce the following result -


Alright guys! This is where we are rounding up for this tutorial post. In my next tutorial guide, we are going to be discussing about PHP Form Validation.

Feel free to ask your questions where necessary and i will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.

Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.

Thanks for reading and bye for now.


Post a Comment

Hello dear readers! Please kindly try your best to make sure your comments comply with our comment policy guidelines. You can visit our comment policy page to view these guidelines which are clearly stated. Thank you.