Final Question 19 - 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 Final Question 19.php

  1. <?php
  2. session_start();   //no idea if any of this actually works
  3. ?>
  4. <!DOCTYPE HTML>  
  5. <html>
  6. <head>
  7. </head>
  8. <body>  
  9.  
  10. <?php
  11. // define variables and set to empty values
  12. $name = $rate_of_pay = $hours_worked = $relations = "";
  13.  
  14. if ($_SERVER["REQUEST_METHOD"] == "POST") {
  15.   $name = test_input($_POST["name"]);
  16.   $rate_of_pay = test_input($_POST["rate_of_pay"]);
  17.   $hours_worked = test_input($_POST["hours_worked"]);
  18.   $relations = test_input($_POST["relations"]);
  19. }
  20.  
  21. function test_input($data) {
  22.   $data = trim($data);
  23.   $data = stripslashes($data);
  24.   $data = htmlspecialchars($data);
  25.   return $data;
  26. }
  27. ?>
  28.  
  29. <h2>Payroll stuff</h2>
  30. <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">  
  31.   Name: <input type="text" name="name">
  32.   <br><br>
  33.   Rate of Pay: <input type="text" name="rate_of_pay">
  34.   <br><br>
  35.   Hours Worked: <input type="text" name="hours_worked">
  36.   <br><br>
  37.     Relations:
  38.   <input type="radio" name="relations" value="Single">Single
  39.   <input type="radio" name="relations" value="Married">Married
  40.   <br><br>
  41.     <input type="submit" name="submit" value="Submit">
  42. </form>
  43.  
  44. <?php
  45. $_SESSION["name"] = $name;
  46. $_SESSION["rate_of_pay"] = $rate_of_pay;
  47. $_SESSION["hours_worked"] = $hours_worked;
  48. $_SESSION["relatons"] = $relatons;
  49. ?>
  50.  
  51. </body>
  52. </html>
  53.  
File Description
  • Final Question 19
  • PHP Code
  • 14 Apr-2021
  • 1.25 Kb
You can Share it: