Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help with a three step homework: Let’s practice working with control stru

ID: 3598349 • Letter: I

Question

I need help with a three step homework:

Let’s practice working with control structures by modifying a PHP script. In Chapter 6 of our textbook we use the handle_reg.php file to demonstrate the use of if, switch, and loop statements. After working with the examples in the chapter, modify the handle_reg.php to do the following:

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

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

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

I need to submit the three modified PHP script files.

Explanation / Answer

<!DOCTYPE HTML>  
<html>
<head>
</head>
<body>  

<?php
// define variables and set to empty values
$name = $email = $gender = $comment = $website = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
  $name = test_input($_POST["name"]);
  $email = test_input($_POST["email"]);
  $website = test_input($_POST["website"]);
  $comment = test_input($_POST["comment"]);
  $gender = test_input($_POST["gender"]);
}

function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}
?>

<h2>PHP Form Validation Example</h2>
<form method="post" action="<?php echohtmlspecialchars($_SERVER["PHP_SELF"]);?>">  
  Name: <input type="text" name="name">
  <br><br>
  E-mail: <input type="text" name="email">
  <br><br>
  Website: <input type="text" name="website">
  <br><br>
  Comment: <textarea name="comment" rows="5" cols="40"></textarea>
  <br><br>
  Gender:
  <input type="radio" name="gender" value="female">Female
  <input type="radio" name="gender" value="male">Male
  <br><br>
  <input type="submit" name="submit" value="Submit">  
</form>

<?php
echo "<h2>Your Input:</h2>";
echo $name;
echo "<br>";
echo $email;
echo "<br>";
echo $website;
echo "<br>";
echo $comment;
echo "<br>";
echo $gender;
?>

</body>
</html>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote