HTML form with PHP handler Every fall local dog rescue organizes a fundraiser fo
ID: 3790283 • Letter: H
Question
HTML form with PHP handler
Every fall local dog rescue organizes a fundraiser for the dogs. Participants register and pay a small fee to walk their dog, and the proceeds go to the rescue animals. Create a "Walk Your Dog" registration form that stores participants' name, their dog name, dog breed, and e-mail address in a text le. The file will be stored in the same directory as your program. Please do not hardcode the path. Include functionality (button) that allows rescue workers to view the file and prevent the same participant's name from being entered twice.
Your entry in the text file should look like this:
John Smith, Fido, GSD, johnsmith@whatever.com
Sally Brown, Maggie, chihuahua, sally@wherever.com
The text file entry should have commas, and the above formatting, that is, all the necessary spaces should be there, new entry on the new line.
Explanation / Answer
Hi,
Here, is the HTML code:
<!DOCTYPE html>
<html>
<head>
<title> Walk Your Dog </title>
<h1> <center> Walk Your Dog </center> </h1>
</head>
<body>
<form method="POST" action="Dog-info.php">
<p><label>Enter Your name: </label><input type="text" name="name" id="name" /></p>
<p> <label> Enter Your Dogs Name: </label> <input type="text" name="dogname" id="dogname" /></p>
<p> <label> Enter Dogs Breed: </label> <input type="text" name="breed" id="breed" /></p>
<p> <label> Enter Your email: </label><input type="text" name="email" id="email" /></p>
<p><input type="submit" value="Submit" /></p>
</form>
</body>
</html>
And Here's the PHP code:
NOTE: save this PHP file with the name as "Dog-info.php" only in the same folder where html web form is saved.
<?php
$name=$_POST["name"];
$dogname=$_POST["dogname"];
$breed=$_POST["breed"];
$email=$_POST["email"];
$file= fopen("doginfo.txt","a");
$infostring = $name.",".$dogname.",".$breed.",".$email."n";
fwrite($file,$infostring);
fclose($file);
echo "<h1>Your data has been saved in a text file!</h1>"
?>
NOTE: The above PHP code will append the inputs from user to the text file, and to check for duplicacy in the file, first create a .txt log file of the data inputs and simultaneously check the incoming new data and the old data.
If there is any doubt or query feel free to ask
ThanYou for Using Chegg!!!
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.