I really need help with this assignment. The assignment is in PHP code 1 Rewrite
ID: 3598452 • Letter: I
Question
I really need help with this assignment. The assignment is in PHP code
1 Rewrite handle_reg.php so that it uses a variable for the current year, instead of hard-coding that value. Name your file handle_reg_1.php
2 For debugging purposes, add code to the beginning of the handle_reg.php script that prints out the values of the received variables. Hint: There’s a short and a long way to do this. Name your file handle_reg_2.php
3 Update handle_reg.php so that it validates the user’s birthday by looking at the three individual form elements: month, day, and year. Create a variable that represents the user’s birthday in the format XX/DD/YYYY. Hint: You’ll have to use concatenation. Name your file handle_reg_3.php
Submit the three modified PHP script files.
The code that i have is
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Registratio</title>
<style type="text/css" media="screen">
.error { color: red; }
</style>
</head>
<body>
<h1>Registration Results</h1>
<?php // Script 6.2 -handle_reg.php
$okay = true;
if (empty($_POST['email'])) {
print '<p class="error">Please enter your email address.</p>';
$okay = false;
}
if (empty($_POST['password'])) {
print '<p class="error">Please enter your password.</p>';
$okay = false;
}
if (is_numeric($_POST['year'])) {
$age = 2017 - $_POST['year'];
} else {
print '<p class="error">Please enter the year you were born as four digits.</p>';
$okay = false;
}
if ($okay) {
print '<p> You have been successfully registered(but not really).</p>';
print "<p>You will turn $age this year.</p>";
}
?>
</body>
</html>
Explanation / Answer
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Registratio</title>
<style type="text/css" media="screen">
.error { color: red; }
</style>
</head>
<!-- this part is used for test the output
<form method="POST">
<input type="text" name='email'><br>
<input type="password" name='password'><br>
<input type="text" name='year'><br>
<input type="submit" value='calculate your age'>
</form>
-->
<body>
<h1>Registration Results</h1>
<?php // Script 6.2 -handle_reg.php
$okay = true;
if (empty($_POST['email'])) {
print '<p class="error">Please enter your email address.</p>';
$okay = false;
}
if (empty($_POST['password'])) {
print '<p class="error">Please enter your password.</p>';
$okay = false;
}
// we are using date function to get current year date("Y") here Y represent year.
if (is_numeric($_POST['year'])) {
$age = date("Y") - $_POST['year'];
} else {
print '<p class="error">Please enter the year you were born as four digits.</p>';
$okay = false;
}
if ($okay) {
print '<p> You have been successfully registered(but not really).</p>';
print "<p>You will turn $age this year.</p>";
}
?>
</body>
</html>