I have one html form as index.php and also another mydata.php file. I want to put data into mydata.php file, but there is some issue
index.php
<form action="" method="POST">
<input name="field1" type="text" />
<input name="field2" type="text" />
<input type="submit" name="submit" value="Save Data">
</form>
<?php
if (isset($_POST['field1']) && isset($_POST['field2'])) {
if (!filesize('mydata.php')) {
$data0 = '<?php $a = array(' . "
";
$ret = file_put_contents('mydata.php', $data0, FILE_APPEND | LOCK_EX);
}
$data = '"' . $_POST['field1'] . '"' . '=>' . '"' . $_POST['field2'] . '",' . "
";
$ret = file_put_contents('mydata.php', $data, FILE_APPEND | LOCK_EX);
if ($ret === false) {
die('There was an error writing this file');
} else {
echo "$ret bytes written to file";
}
}
?>
mydata.php
$array = array("a"=>"b");
When I add submit new value i want to need push new array like my post data
Array
(
[field1] => c
[field2] => d
[submit] => Save Data
)
$array = array("a"=>"b","c"=>"d");