Storing user information in a text file
<html>
<body>
<?
$form ="<form action=\"index.php\" method=\"post\">
<input type=\"hidden\" name=\"seenform\" value=\"y\">
<b>Give us your personal info!</b><br>
Your Name:<br>
<input type=\"text\" name=\"name\" value=\"\"><br>
Your Email:<br>
<input type=\"text\" name=\"email\" value=\"\"><br>
Your Preferred Language:<br>
<select name=\"language\">
<option value=\"\">Choose a language:
<option value=\"English\">English
<option value=\"Spanish\">Spanish
</select><br>
Your Occupation:<br>
<select name=\"job\">
<option value=\"\">What do you do?:
<option value=\"student\">Student
<option value=\"programmer\">Programmer
</select><br>
<input type=\"submit\" value=\"submit!\">
</form>";
if ($seenform != "y") :
print "$form";
else :
$fd = fopen("user_information.txt", "a");
$name = str_replace("|", "", $name);
$email = str_replace("|", "", $email);
$user_row = $name."|".$email."|".$language."|".$job."\n";
fwrite($fd, $user_row) or die("Could not write to file!");
fclose($fd);
print "Thank you!";
endif;
?>
</body>
</html>
Related examples in the same category