I am getting a warning inside the browser debugger, but the PHP still works. Why am I getting a warning? Thanks in advance.
Warning: Invalid argument supplied for foreach().
HTML:
<form action="" method="post" name="savefile">
<input id="uniqueID" value="ZF4446A3GZ" name="filename" type="text">
<input name="textdata[]" type="text">
<input name="textdata[]" type="text">
<input name="textdata[]" type="text">
<input value="Done!" name="submitsave" type="submit">
</form>
PHP:
<?php
if (isset($_POST)){
foreach($_POST["textdata"] as $text){
if(!file_exists($_POST['filename'] . ".txt")){
$file = tmpfile();
}
$file = fopen($_POST['filename'] . ".txt","a+");
while(!feof($file)){
$old = $old . fgets($file);
}
file_put_contents($_POST['filename'] . ".txt", trim($text).PHP_EOL, FILE_APPEND);
fclose($file);
}
}
?>