Question: PHP PROGRAMMING Every fall local Purple Square organizes a blood drive. Participants donate blood to help people who need blood transfusions. Use the techniques you
PHP PROGRAMMING
Every fall local Purple Square organizes a blood drive. Participants donate blood to help people who need blood transfusions. Use the techniques you learned in Chapter 6 to create a "Save A Life" registration form that stores donor's name, their age, blood type, Rh D, and whether the person is a universal donor, or a universal recipient, in a text data le named data.txt.The data file will be stored in a directory named Donors on your C drive. This directory is created by your program. Donor's name should only allow letters, age should only allow numbers, Blood type will allow "A", "B", "AB", and "O". Rh will allow only "POS" and "NEG".
A universal donor is a person with blood type O Rh D NEG, that blood can be given to a recipient with any blood type. Two start will indicate if a person is a universal donor. Three stars indicate a universal recipient. Universal recipients have blood type AB Rh D POS, and can receive blood of any type. In your program you will have to determine that, and print the stars accordingly.
Include functionality (button) that allows rescue workers to view the file on the screen and prevent the same donor's name from being entered twice. Your entry in the text file should look like the example below. Each entry should have commas, and the above formatting, that is, all the spaces should be there, new entry on the new line. The entry previewed on the screen should also look well-organized, with each entry on the new line. The output should be displayed in a nice form no matter what computer is used to run it. You can decide how you want to do this.
Text file data will look like this:
Name, Age, Blood Type, Rh D, UD/UR John Smith, 23, A, POS Sally Brown, 31, AB, POS, *** Mary Pinkerton, 26, O, NEG, **
MY PHP CODE ------------------------------
//Variables for the record that is being created
$error = '';
$name = '';
$age = '';
$bloodtype = '';
$rhd = '';
$star = '';
function clean_text($string)
{
$string=trim($string);
$string=stripslashes($string);
$string=htmlspecialchars($string);
return $string;
}
// The text file being created
$myfile ="data.txt";
$handle = fopen($myfile, 'a+') or die ('Cannot open file: ' . $myfile);
//opening the file.
if(isset($_POST["submit"]))
{
if(empty($_POST["name"]))
{
$error = '
';}
else
{
$name = clean_text($_POST["name"]);
if(!preg_match("/^[a-zA-Z ]*$/",$name))
{
$error = '
';}
}
if(empty($_POST["age"]))
{
$error = '
';}
else
{
$age = clean_text($_POST["age"]);
if(!preg_match("/^[0-9]*$/",$age))
{
$error = '
';}
}
if(empty($_POST["bloodtype"]))
{
$error = '
';}
else
{
$bloodtype = $_POST["bloodtype"];
}
if(empty($_POST["rhd"]))
{
$error = '
';}
else
{
$rhd = $_POST["rhd"];
}
if($error == '')
{
$file_open = fopen("data.txt", "a");
$no_rows = count(file("data.txt"));
if($no_rows > 1)
{
$no_rows = ($no_rows - 1) + 1;
}
if ($bloodtype == 'O' && $rhd == 'NEG')
{
$star = '**';
}
elseif ($bloodtype == 'AB' && $rhd == 'POS')
{
$star = '***';
}
$form_data = ['Donors name' => $name,
'Age' => $age,
'Blood Type' => $bloodtype,
'RH D' => $rhd,
'UD/UR' => $star
];
fputcsv($file_open, $form_data);
$error = '';
$name = '';
$age = '';
$bloodtype = '';
$rhd = '';
$star = '';
}
feof;
?>
-----------HTMLCODE-------------------------
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
content="text/html; charset=iso-8859-1" />
Blood Drive Registry
---------------- HOW DO I GET THE PHP FILE TO ACCEPT THE DATA THAT IS ENTERED INTO HTML FILE TO READ BACK THE INFORMATION THAT IS STORED INTO THE PHP FILE IN A TEXT FILE.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
