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 to read a csv file in php and make a html table? I can't use...
how to read a csv file in php and make a html table? I can't use the PHP function fgetcsv. I can use explode. I can't put a php inside a php. Acme,Walmart,Ross,BJs,Target,Marshalls,Foot Locker,Giant,Charming Charlie 142,160,28,10,5,3,60,0.28,3167 175,180,18,8,4,1,12,0.43,4033 129,132,13,6,3,1,41,0.33,1471 138,140,17,7,3,1,22,0.46,3204 232,240,25,8,4,3,5,2.05,3613 135,140,18,7,4,3,9,0.57,3028 150,160,20,8,4,3,18,4.00,3131 207,225,22,8,4,2,16,2.22,5158 271,285,30,10,5,2,30,0.53,5702 89,90,10,5,3,1,43,0.30,2054 153,157,22,8,3,3,18,0.38,4127 87,90,16,7,3,1,50,0.65,1445 234,238,25,8,4,2,2,1.61,2087 106,116,20,8,4,1,13,0.22,2818 175,180,22,8,4,2,15,2.06,3917 165,170,17,8,4,2,33,0.46,2220 166,170,23,9,4,2,37,0.27,3498 136,140,19,7,3,1,22,0.63,3607 <!DOCTYPE html> <html> <head>    <meta charset="utf-8">    <title>Stores</title>    <link rel="stylesheet" href="style.css"> </head> <body> <h1>Stores</h1> <?php <table> <tr> <th>Acme</th> <th>Walmart</th> <th>Ross</th> <th>BJs</th> <th>Target</th> <th>Marshalls</th> <th>Foot Locker</th>...
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?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT