My task is to put data from a form with 24 input fields into a txt file. Not very adapt at PHP coding I got a few snippets of code from the web, the file_put_content
snippet from an example with 2 input fields. It worked (=it wrote data to file and showed the 'thank_you'-page). I added another field - it worked. Ok, so now I added all my fields - it did not write to file and produced a blank white page.
I went back to the 3 fields version, and started adding fields 1 by 1. When it stopped working at 8 fields, I introduced a 2. isset(POST[])
element. That way I could add another 6 fields, and it worked. (In between I separately saved the code when it successfully printed data from 11 fields to my file). When on the 7th field it again produced a blank page and did not save to file, I removed tha last addition - and to my BIG SURPRISE the very code that had worked before I added the last one didn't work any more?! I continued to remove element by element - it didn't work anymore?! So I reverted to the saved version of the code - and it still does not work.
So I went over every single letter, sign and number - all to no avail. Even though I havent changed anything in the html form, I ched this too, because everything points to a problem in the form that points to my php file. All in vain. I am aware that it has to be something I did and now overlook - please point out to me where my mistake lies.
This is the version that worked 2 days ago, and I saved it before expanding:
<?php
function resetForm($form) {
$form.find('input:text, input:password, input:file, select, textarea').val('');
$form.find('input:radio, input:checkbox')
.removeAttr('checked').removeAttr('selected');
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
if(isset($_POST['q01' | 'q02' | 'q03' | 'q04' | 'q05' | 'q06' | 'q07']) && isset($_POST['q08' | 'q09' | 'q99' | 'q98'])) {
$data = $_POST['q01'] . '#' . $_POST['q02'] . '#' . $_POST['q03'] . '#' . $_POST['q04'] . '#' . $_POST['q05'] . '#' . $_POST['q06'] . '#' . $_POST['q07'] . '#' . $_POST['q08'] . '#' . $_POST['q09'] . '#' . $_POST['q99'] . '#' . $_POST['q98'] . "\n";
$ret = file_put_contents('data/data.txt', $data, FILE_APPEND | LOCK_EX);
if($ret === false) {
die('There was an error writing this file');
}
else {
header('Location:danke.html');
}
exit (0);
}
?>
Just to make sure I will also post the relevant lines of the form:
<form id="umfrage" class="appnitro" method="post" action="data2text.php" accept-charset="UTF-8">
<input id="saveForm" class="button_text" type="submit" name="submit" value="Fertig!" />