I need help with storing data in a txt file

I have a form for the user to input several pieces of data. When they submit the form, I need to append the data to a txt file. The form works well, but I can’t get it to append the data to the txt file. Here are the lines of my code:

$file = “member.txt”;
$data = $name.’|’$var1.’|’.$var2.’|’.$var3.’|’.$var4.’|’.$var5;
$myfile = file_put_contents($file, $data.PHP_EOL , FILE_APPEND | LOCK_EX);

Any help would be greatly appreciated.

Where are your var variables magically appearing from?

Some are from my database and a couple are calculate in the script itself.

Your going to have to show more of your code than that. How are you getting your form submissions into variables?

If you are already using a database, just insert this information in a database table.

If the file_put_contents is actually being called and is failing, it will return a false value and there would be a php error message telling you why it failed. Do you have php’s error_reporting set to E_ALL and display_errors set to ON, preferably in the php.ini on your system, so that php will help you by reporting and displaying all the errors it detects?

BTW - if you are not doing anything to prevent http(s) requests to the text file, anyone can request it and see the entire contents. Do you really want that to occur?

Sponsor our Newsletter | Privacy Policy | Terms of Service