In: Computer Science
Assignment 2:
Note: To receive credit, the files need to work as expected and be error free.
This is just an example to give you an idea of what Assignment 2 is supposed to do. You can use this example if you wish for your assignment:
HTML file form to get user input, save the file as index.html:
<html>
<head></head>
<title>HTML+ PHP </title>
<link href="style.css" type="text/css"
rel="stylesheet"/>
<body>
<form action="process.php" method="POST">
<input type="text" name="fname" placeholder =" Enter your first
name : "><br>
<input type="text" name="lname" placeholder =" Enter your last
name : "><br>
<input type="text" name="score1" placeholder =" Enter
score1"><br>
<input type="text" name="score2" placeholder =" Enter score2
"><br>
<input type="text" name="score3" placeholder =" Enter
score3"><br>
<input type="submit" value="Submit"><br>
</form>
</body>
</html>
--------------------------------------------------------------------------------------------
Use the below file as style sheet for html.css file
Save the below file as style.css
input[type="text"]
{
width: 200px;
border: 2px solid #aaa;
border-radius: 3px;
margin: 8px 0;
padding:8px 0;
}
input[type="submit"]
{
width: 200px;
box-shadow: 0 0 8px 0 dodgerBlue;
border-radius: 3px;
margin: 8px 0;
padding:8px 0;
}
--------------------------------------------------------------------------------------------
Php file to process the input get by the index.html file and display the values of first name, last name, and average score values.
Save the below file as "process.php"
<?php
//Get values of score1 , score2 and score3
$s1=$_POST['score1'];
$s2=$_POST['score2'];
$s3=$_POST['score3'];
//Calculate the average of three values
$result=($s1+$s2+$s3)/3.0;
$result=number_format($result);
echo "First Name : ",$_POST['fname']."<br>";
echo "Last Name : ",$_POST['lname']."<br>";
echo "Average : ",$result."<br>";
?>
--------------------------------------------------------------------------------------------
Sample Output:
Input form :
Click on Submit button. The result will display as follows process.php
Note: To run the PHP files, apache server must be run in the background before running the files (Use xamp, start the apache server).