Skip to content

Instantly share code, notes, and snippets.

@morad7
Created September 27, 2017 21:18
Show Gist options
  • Save morad7/fca031e98a1c9e99e399a4db1a77566c to your computer and use it in GitHub Desktop.
Save morad7/fca031e98a1c9e99e399a4db1a77566c to your computer and use it in GitHub Desktop.
Form to file php code
<!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