I've been at this for a while and been through other options on stack but can't get this to work. (I'm pretty nooby, sorry!)
I have a form which i want to send data to my txt file but it's just not writing.
ANY help greatly appreciated, thank you!!
My HTML Form:
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>php test</title>
</head>
<title></title>
</head>
<body>
<form action="myprocessingscript.php" method="POST">
<input name="field1" type="text" />
<input name="field2" type="text" />
<input type="submit" name="submit" value="Save Data">
</form>
<a href='/tmp/mydata.txt'>Text file</a>
</body>
And my PHP
<?php
if(isset($_POST['field1']) && isset($_POST['field2'])) {
$data = $_POST['field1'] . '-' . $_POST['field2'] . "\n";
$ret = fwrite('/tmp/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');
}