Created
September 27, 2017 21:18
-
-
Save morad7/fca031e98a1c9e99e399a4db1a77566c to your computer and use it in GitHub Desktop.
Form to file php code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title></title> | |
</head> | |
<body> | |
<form action=<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?> method="POST"> | |
<input name="field1" type="text" /> | |
<input name="field2" type="text" /> | |
<input type="submit" name="submit" value="Save Data"> | |
</form> | |
<?php | |
if(isset($_POST['field1']) && isset($_POST['field2'])) { | |
$data = $_POST['field1'] . '-' . $_POST['field2'] . "\n"; | |
$ret = file_put_contents('mydata.txt', $data, FILE_APPEND | LOCK_EX); | |
if($ret === false) { | |
die('There was an error writing this file'); | |
} | |
else { | |
echo "$ret bytes written to file"; | |
} | |
} | |
else { | |
die('no post data to process'); | |
} | |
?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment