Question

In: Computer Science

need mainly the php file and how to do the "value" portion use pregmatch to verify...

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.

  1. "first_name"
  2. "last_name"
  3. "user_id"
  4. "values"

The following rules must be enforced by your PHP script about the input.

  • No field is allowed to be blank.
  • Maximum length of first and last name is 20 characters.
  • The first and last names should be only made up of alphabetical characters. (no numbers or symbols). Only a-z, and A-Z. Any ordering of lower/uppercase letters is acceptable.
  • User ID must be 3 lowercase letters followed by 3 numbers. Example: abc123
  • Values has a max length of 50 characters. It is a comma separated list of values, with each value in the range 0.0 to 100.0.
  • Every value must have 1 digit after the decimal point.
  • Every value must have 1,2, or 3 digits before the decimal point (i.e. .7 is not a valid value in our system, but 0.7 is valid).
  • Here is an example of input to the values field:

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.

Solutions

Expert Solution

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.";

}

?>


Related Solutions

How do you verify if a claim is Workers’ Compensation?
How do you verify if a claim is Workers’ Compensation?
How to formulate a hypothesis? and test and verify it? ( i need very good EXAMPLES...
How to formulate a hypothesis? and test and verify it? ( i need very good EXAMPLES thank you)
How do professional analysts value assets. Why do they use these measures?
How do professional analysts value assets. Why do they use these measures?
How do businesses use value chains to discover opportunities?
How do businesses use value chains to discover opportunities?
(PHP and MySQL) How do you determine what size (in terms of subtype or length) a...
(PHP and MySQL) How do you determine what size (in terms of subtype or length) a column should be? What are some of the other properties that can be assigned to columns? What is a primary key? if you`re using the command-line myaql client to connect to MySQL,What username and password combination is required?
*****NOTE: I DO NOT NEED A DRIVER FILE. I NEED mixed.h AND mixed.cpp********* *****PLEASE MAKE SURE...
*****NOTE: I DO NOT NEED A DRIVER FILE. I NEED mixed.h AND mixed.cpp********* *****PLEASE MAKE SURE THAT mixed.h AND mixed.cpp WORK WITH THE DRIVER FILE PROVIDED******************* Objective: Upon completion of this program, you should gain experience with overloading basic operators for use with a C++ class. The code for this assignment should be portable -- make sure you test with g++ on linprog.cs.fsu.edu before you submit. Task Create a class called Mixed. Objects of type Mixed will store and manage...
PYTHON #What you need to do is to transform the file Mkt_data_test.txt #to the format like...
PYTHON #What you need to do is to transform the file Mkt_data_test.txt #to the format like in file in the screenshot # #Your steps to get there: #1.Create a header line with following columns: Time;Bid\Ask;Price;Volume. NOTE NO SPACES #2.Remove all of the timestamp lines, i.e ======== Data: ..... #3.Remove the 1900-01-01 from the timestamp but leave the time itself #4.Get rid of all spaces and empty lines #5.Replace 0 or 1 in the second position with Bid or Ask, Bid...
I need this in an excel file with formulas please: 1) Use an Excel spreadsheet to...
I need this in an excel file with formulas please: 1) Use an Excel spreadsheet to solve problem #31 (the PUTZ, Inc. project) for Chapter 10 in the textbook. 2) Conduct a sensitivity analysis that focuses on the sales price by increasing the price by 10% above the best estimate, and then by decreasing the price by 10% below the best estimate. 3) You must provide one spreadsheet for each of the three situations—the base case estimate, the best case,...
How can websites keep track of users? Do they always need to use cookies?
How can websites keep track of users? Do they always need to use cookies?
Can someone explain how the heated concrete snow melting system works? mainly I need the formula...
Can someone explain how the heated concrete snow melting system works? mainly I need the formula used to express how the heat of the concrete melts the snow. Thank you
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT