Page 301 - Computer Software Application TP - Volume 1
P. 301

COMPUTER SOFTWARE APPLICATION - CITS





           TASK 3: Importing user input and accessing user input
           I  Create an HTML Form
              1  Open the text editor
              2  Write the following codes



                 <html
              <head>
                      <title>PHP User Input</title>
              </head>

              <body>
                <h2>Enter your name:</h2>
                <form action=”process.php” method=”get”>
                         <input type=”text” name=”name” placeholder=”Enter your    name”>
                         <button type=”submit”>Submit</button>

                 </form>
              </body>
              </html>
              3  Save the program in C:\Apache24\htdocs in a folder as index.html



           II  Create a PHP script that acquires user input
              1  Open the text editor
              2  Write the following codes
                           <html>

                           <body>
                        <?php
                      if ($_SERVER[“REQUEST_METHOD”] == “GET”)
                      {
                   // Check if the name field is set and not empty
                   if (isset($_GET[“name”]) && !empty($_GET[“name”]))

                                                       {
                                 $name = $_GET[“name”];
                                 // Display a greeting message
                                 echo “Hello, $name! Welcome!”;

                   }
                  else
                  {
                                 // If name field is empty, display an error message
                                 echo “Please enter your name!”;

                   }


                                                           286

                               CITS : IT & ITES - Computer Software Application - Exercise 56
   296   297   298   299   300   301   302   303   304   305   306