In: Computer Science
Q 3 b)
In this question you must write a php script to take Name[input = text], Country[input = select, card_number[input = number], and type of card[input = radio button]to get user's input. The name of this file will be payment.php.
Once the user submits the form; you must direct all the information to cust_info.html.
The task is to keep a record in the cust_info.html of all the users who fill the forms and hit submit.
the output must populate the list in the form of;
Tiger Woods; CA;123456789123545698; VISA
Lucky Mann; FL; 2365415698712365478; MASTER CARD
...............................................
..............................................
up to six forms of info.
Alert: you can only use PHP and HTML. NO JavaScript or database [20 points]
files: cust_info.html (it will be edited by php , create a blank file with this name)
Payment.php
<?php
//echo("hhhh");
if (isset($_POST['submit'])) {
//Saving data into a file named cust_info.html
$myfile = fopen("cust_info.html", "a") or die("Unable to open file!");
$file_data=$_POST['Name'].";".$_POST['Country'].";".$_POST['card_number'].";".$_POST['type_of_card']."<br>\n";
$file_data .= file_get_contents('cust_info.html');
file_put_contents('cust_info.html', $file_data);
// fwrite($myfile, $data1);
fclose($myfile);
header("Location: cust_info.html");
}
?>
<!DOCTYPE html>
<html>
<body>
<h3>Enter Payment Information</h3>
<div>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method=post>
<label for="name">First Name</label>
<input type="text" id="name" name="Name" placeholder="Your name.." required>
<label for="country">Country</label>
<select id="country" name="Country">
<option value="au">Australia</option>
<option value="ca">Canada</option>
<option value="usa">USA</option>
<option value="In">India</option>
</select>
<label for="cnum">Card number</label>
<input type="number" id="cnum" name="card_number" placeholder="" required>
<p>Type of Card</p>
<input type="radio" id="master" name="type_of_card" value="MASTER CARD" required>
<label for="master">Master Card</label><br>
<input type="radio" id="visa" name="type_of_card" value="VISA" checked>
<label for="visa">VISA</label><br>
<input type="submit" value="submit" name="submit">
</form>
</div>
<style>
input[type=text], select,input[type=number] {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
input[type=submit] {
width: 100%;
background-color: #4CAF50;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
border-radius: 4px;
cursor: pointer;
}
input[type=submit]:hover {
background-color: #45a049;
}
div {
border-radius: 5px;
background-color: #f2f2f2;
padding: 20px;
}
</style>
</body>
</html>