Week 9-10 Question 9 - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of Week 9-10 Question 9.php

  1. <!DOCTYPE HTML>
  2. <html>  
  3. <body>
  4. <?php
  5. $name = $room = $in_name = $in_email = "";
  6. $nameErr = $roomErr = $in_nameErr = $in_emailErr = "";
  7. if ($_SERVER["REQUEST_METHOD"] == "POST") {
  8.   if (empty($_POST["name"])) {
  9.     $nameErr = "Name is required";
  10.   } else {
  11.     $name = test_input($_POST["name"]);
  12.   }
  13.  
  14.   if (empty($_POST["email"])) {
  15.     $in_emailErr = "Email is required";
  16.   } else {
  17.     $in_email = test_input($_POST["email"]);
  18.   }
  19.  
  20.   if (empty($_POST["room"])) {
  21.     $roomErr = "Room number required";
  22.   } else {
  23.     $room = test_input($_POST["website"]);
  24.   }
  25.   
  26.   if (empty($_POST["instructors name"])) {
  27.     $in_nameErr = "intructors name required";
  28.   } else {
  29.     $in_name = test_input($_POST["intructors name"]);
  30.   }
  31. }
  32.   ?>
  33.  
  34. <form method="POST" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
  35. Course Name: <input type="text" name="name" value="<?php echo $name;?>"><br>
  36. Room Number: <input type="text" name="room number" value="<?php echo $room;?>"><br>
  37. Instructors Name: <input type="text" name="instructors name" value="<?php echo $in_name;?>"><br>
  38. Instructors E-mail: <input type="text" name="instructors email" value="<?php echo $in_email;?>"><br>
  39. <input type="submit">
  40. </form>
  41. <?php
  42. echo "Welcome $in_name to the following Course $name, in room $room, and email $in_email";
  43. ?>
  44. </body>
  45. </html>
File Description
  • Week 9-10 Question 9
  • PHP Code
  • 07 Apr-2021
  • 1.29 Kb
You can Share it: