In: Computer Science
I want the code in the following three PHP files without any CSS. Thank you
Create a Input.php.
Create a PHP script that will perform the following tasks:
1. Divide the content area of this page into two sections (Side by Side)
2. On the left side: create a form that accepts the following information from the user
a. Text box, Employee Name
b. Text box, Employee ID
c. Text box, Telephone Number
d. Text box, Email Address
e. Radio Button List, with the values Manager, Team Lead, IT Developer, and IT Analyst
f. Select, a multiple select box that lists 4 IT projects: Project A, Project B, Project C, Project D
g. Submit button with the text ‘Submit Information’
3. On the right side: When the user clicks 'Submit Information' gather all the information from the form on the left side and display the results on the right side
Create a Session1.php
Create a PHP script that will perform the following tasks:
1. Implement the same form listed in Input.php, Part 2
2. This time, when the user clicks 'Submit Information' , store all the information gathered from the form in the Session State
3. Automatically Redirect the user to Session2.php
Create a Session2.php
Once the user is forwarded to Session2.php, display the results of the information gathered in the form on Session2.php
NOTE: Forms, Session_RetrieveValues.php, Session_StoreValues.php provide examples of how to do all of these things.
Part 1 :
CODE :
input.php
<!DOCTYPE HTML>
<html>
<head>
<style>
.column {
text-align:center;
float: left;
width: 50%;
}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
</style>
</head>
<body>
<?php
// define variables and set to empty values
$employeeName = $email = $post = $employeeID = $phone = $project = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$employeeName=test_input($_POST["employeeName"]);
$employeeID = test_input($_POST["employeeID"]);
$email = test_input($_POST["email"]);
$phone = test_input($_POST["phone"]);
$post = test_input($_POST["post"]);
$project=test_input($_POST['project']);
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<div class="row">
<div class="column">
<h2>PHP </h2>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
Employee Name: <input type="text" name="employeeName" value="<?php echo $employeeName;?>">
<br><br>
Employee ID: <input type="text" name="employeeID" value="<?php echo $employeeID;?>">
<br><br>
Telephone Number: <input type="text" name="phone" value="<?php echo $phone;?>">
<br><br>
E-mail: <input type="text" name="email" value="<?php echo $email;?>">
<br><br>
Post:
<input type="radio" name="post" <?php if (isset($post) && $post=="Manager") echo "checked";?> value="manager">Manager
<input type="radio" name="post" <?php if (isset($post) && $post=="TeamLead") echo "checked";?> value="Team Lead">Team Lead
<input type="radio" name="post" <?php if (isset($post) && $post=="itDeveloper") echo "checked";?> value="IT Developer">IT Developer
<input type="radio" name="post" <?php if (isset($post) && $post=="itAnalyst") echo "checked";?> value="IT Analyst">IT Analyst
<br><br>
<label for="project">Choose a project: </label>
<select name="project" id="project">
<option value="Poject A">Project A</option>
<option value="Project B">Project B</option>
<option value="Project C">Project C</option>
<option value="Project D">Project D</option>
</select>
<br><br>
<input type="submit" name="submit" value="Submit Information">
</form>
</div>
<div class="column">
<?php
echo "<h2>Submitted Information</h2>";
echo "<label>Employee Name : </label>";
echo $employeeName;
echo "<br>";
echo "<label>Employee ID : </label>";
echo $employeeID;
echo "<br>";
echo "<label>Telephone Number : </label>";
echo $phone;
echo "<br>";
echo "<label>Email Address: </label>";
echo $email;
echo "<br>";
echo "<label>Post : </label>";
echo $post;
echo "<br>";
echo "<label>Project : </label>";
echo $project;
?>
</div>
</div>
</body>
</html>
SCREENSHOT :
OUTPUT :
Part 2 :
Session1.php
CODE :
<!DOCTYPE HTML>
<html>
<head>
<style>
</style>
</head>
<body>
<?php
// define variables and set to empty values
$employeeName = $email = $post = $employeeID = $phone = $project = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
session_start();
$employeeName=test_input($_POST["employeeName"]);
$employeeID = test_input($_POST["employeeID"]);
$email = test_input($_POST["email"]);
$phone = test_input($_POST["phone"]);
$post = test_input($_POST["post"]);
$project=test_input($_POST['project']);
$_SESSION['employeeName']=$employeeName;
$_SESSION['employeeID']=$employeeID;
$_SESSION['email']=$email;
$_SESSION['phone']=$phone;
$_SESSION['post']=$post;
$_SESSION['project']=$project;
?>
<script type="text/javascript">
window.location="session2.php";
</script>
<?php
exit();
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<h2>PHP </h2>
<form method="post">
Employee Name: <input type="text" name="employeeName" value="<?php echo $employeeName;?>">
<br><br>
Employee ID: <input type="text" name="employeeID" value="<?php echo $employeeID;?>">
<br><br>
Telephone Number: <input type="text" name="phone" value="<?php echo $phone;?>">
<br><br>
E-mail: <input type="text" name="email" value="<?php echo $email;?>">
<br><br>
Post:
<input type="radio" name="post" <?php if (isset($post) && $post=="Manager") echo "checked";?> value="manager">Manager
<input type="radio" name="post" <?php if (isset($post) && $post=="TeamLead") echo "checked";?> value="Team Lead">Team Lead
<input type="radio" name="post" <?php if (isset($post) && $post=="itDeveloper") echo "checked";?> value="IT Developer">IT Developer
<input type="radio" name="post" <?php if (isset($post) && $post=="itAnalyst") echo "checked";?> value="IT Analyst">IT Analyst
<br><br>
<label for="project">Choose a project: </label>
<select name="project" id="project">
<option value="Poject A">Project A</option>
<option value="Project B">Project B</option>
<option value="Project C">Project C</option>
<option value="Project D">Project D</option>
</select>
<br><br>
<input type="submit" name="submit" value="Submit Information">
</form>
</body>
</html>
Session2.php
CODE :
<!DOCTYPE HTML>
<html>
<head>
<style>
</style>
</head>
<body>
<?php
// define variables and set to empty values
$employeeName = $email = $post = $employeeID = $phone = $project = "";
session_start();
$employeeName=$_SESSION['employeeName'];
$employeeID = $_SESSION['employeeID'];
$email = $_SESSION['email'];
$phone = $_SESSION['phone'];
$post = $_SESSION['post'];
$project=$_SESSION['project'];
echo "<h2>Submitted Information</h2>";
echo "<label>Employee Name : </label>";
echo $employeeName;
echo "<br>";
echo "<label>Employee ID : </label>";
echo $employeeID;
echo "<br>";
echo "<label>Telephone Number : </label>";
echo $phone;
echo "<br>";
echo "<label>Email Address: </label>";
echo $email;
echo "<br>";
echo "<label>Post : </label>";
echo $post;
echo "<br>";
echo "<label>Project : </label>";
echo $project;
?>
</body>
</html>
SCREENSHOT CODE :
session1.php
session2.php
OUTPUT :
Please provide feedback and comment down if any problem persists.