I have some basic code that takes results from a form in a previous page, and encodes it to a text file. For some reason, it encodes it properly, then makes a second array that just has null values.
(There are the same amount of values in each array)
I honestly have no idea what's causing this.
Here is the encode code:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$date = $_POST['date'];
$destination = $_POST['destination'];
$msg = $_POST['msg'];
//TODO the file write here VV, use 'a' instead of 'w' too ADD to the file instead of REWRITING IT.
$arr = [$name,$email,$date,$destination,$msg];
$write = json_encode($arr);
echo $write;
$file = fopen('data.txt', 'a');
fwrite($file, $write);
fclose($file);
// echo $arr[];
?>
Here is the result in the .txt file:
["Simon","[email protected]","0101-01-01T01:01","Ohio","Message here"][null,null,null,null,null]
(It writes them on the same line, if that helps)
I don't want this null array here, as it will mess up some of the things I need to do. Any thoughts?
if ( isset($_POST['name'])) { // all your current code }to only process when there is data.