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

COMPUTER SOFTWARE APPLICATION - CITS





           TASK 4: Combine HTML and PHP code
           1  Open the text editor
           2  Write the following codes
                       <html >

              <head>
                   <title Combine HTML and PHP code </title>
              </head>
              <body>
                    <?php
                         // Check if the form is submitted
                         if ($_SERVER[“REQUEST_METHOD”] == “POST”)
                      {
                         // Check if the name field is set and not empty
                         if (isset($_POST[“name”]) && !empty($_POST[“name”]))
                  {
                                      $name = $_POST[“name”];
                                      // Display a greeting message
                                     echo “<h2>Hello, $name! Welcome!</h2>”;
                         }
                  else
                  {

                                    // If name field is empty, display an error message
                                    echo “<h2>Please enter your name!</h2>”;
                         }
                          }
                         ?>
                         <form action=”<?php echo htmlspecialchars($_SERVER[“PHP_SELF”]); ?>”
                         method=”post”>
                           <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 with .php extension

           4  Run the Apache services from windows services
           5  Open the browser and type the following address
              http://localhost/foldername/
           6  Click the php file to run and verify the output











                                                           288

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