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.
Result of php executing
Full code of Final Question 19.php
- <?php
- session_start(); //no idea if any of this actually works
- ?>
- <!DOCTYPE HTML>
- <html>
- <head>
- </head>
- <body>
- <?php
- // define variables and set to empty values
- $name = $rate_of_pay = $hours_worked = $relations = "";
- if ($_SERVER["REQUEST_METHOD"] == "POST") {
- $name = test_input($_POST["name"]);
- $rate_of_pay = test_input($_POST["rate_of_pay"]);
- $hours_worked = test_input($_POST["hours_worked"]);
- $relations = test_input($_POST["relations"]);
- }
- function test_input($data) {
- $data = trim($data);
- $data = stripslashes($data);
- $data = htmlspecialchars($data);
- return $data;
- }
- ?>
- <h2>Payroll stuff</h2>
- <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
- Name: <input type="text" name="name">
- <br><br>
- Rate of Pay: <input type="text" name="rate_of_pay">
- <br><br>
- Hours Worked: <input type="text" name="hours_worked">
- <br><br>
- Relations:
- <input type="radio" name="relations" value="Single">Single
- <input type="radio" name="relations" value="Married">Married
- <br><br>
- </form>
- <?php
- $_SESSION["name"] = $name;
- $_SESSION["rate_of_pay"] = $rate_of_pay;
- $_SESSION["hours_worked"] = $hours_worked;
- $_SESSION["relatons"] = $relatons;
- ?>
- </body>
- </html>