In: Computer Science
need mainly the php file and how to do the "value" portion
use pregmatch to verify proper format in the php file if able.
Create an HTML form that will accept four fields: first name, last name, user ID, and values. Name this file userInfo.html. There should be a submit and reset button on your html form. Your input fields for your form should be inside of a table. The submit button should send the data to a php file named updateInfo.php. The updateInfo.php file should check the data submitted by the html file for proper formatting. While it is allowable that you may check input on the client side (either HTML or Javascript), you MUST check for valid input on the server using PHP. (It will be easier to test your code if you don’t bother doing any checks on the HTML side – you will have to disable the checks on your own code to test the bad inputs).
***IMPORTANT***
Your POST variables in your HTML file must be labeled as follows. I have written an automated script to run tests on your code, and it depends on the POST variables being labeled correctly within the HTML Form.
The following rules must be enforced by your PHP script about the input.
9.3,100.0,45.5,43.0,0.7,0.0,76.9,1.0
If any field has invalid data, display an error message and a link back to the userInfo.html page. Do not write invalid data to the text file, or to the html table. Ignore all data when an entry is invalid.
If all the fields are valid, your PHP script should save the data into a file named userInfo.txt which should have the following format and be sorted by “last_name”. (Note you will need to read in the existing file’s data and add the new data to your data structure, and sort it before you can write the new file in the proper order). Put each record on its own line. To simplify things, you can assume that Last Names are unique – i.e. you can use the last name as a key for your associative array. (I won’t use two of the same last name when I test your code).
LastName--FirstName--UserID--Min,Max,Average;\n
Here is a sample record (a single line) of what should be in your text file:
Doe--John--abc123--3.4,99.9,45.4;
You can see from this that you will need to process the input values from the user to determine the min value, the max value, and the average. To be clear, you don’t need to store all the values entered, just the minimum, the maximum, and the average.
Once the new data has been received, you should also display ALL data from the text file into an HTML table. The table should be sorted by last name just like the text file. After successfully displaying your table, create a link back to the userInfo.html page. You should have 6 columns in your HTML file, with an appropriate header for each column.
UserInfo.html
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form method="post" action="updateInfo.php/">
first_name:<input type="text" name="first_name">
last_name:<input type="text" name="last_name">
user_id:<input type="text" name="user_id">
values:<input type="text" name="values">
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</form>
</body>
</html>
updateInfo.php
<?php
$first_name = $last_name= $user_id = $values ="";
if(!preg_match("/^[a-zA-Z']+)$/",$first_name));
{
$first_nameErr= "only letters and white spaces are allowed";
}
if(!preg_match("/^[a-zA-Z']+)$/",$last_name));
{
$last_nameErr= "only letters and white spaces are all allowed";
}
if(!preg_match('/^[A-Za-z][A-Za-z0-9]{5,31}$/',$user_id))
{
$user_idErr="Invalid";
}
if(preg_match(^\d*\.?\d*[1-9]+\d*$)|(^[1-9]+\d*\.\d*$/',$values)
{
for($i=0;$i<100;$i++)$post_array[]=array();
{
if(isset($POST["values"]))
{
$post_array[]=$_POST["values"];
}
}
}
else{
$valuesErr="Do not write invalid data to the text file, or to the html table.";
}
?>