I have this very simple code of introducing data from input form into a flat file:
Code: Select all
<?php
if (isset($_POST['submit'])) {
$name1 = $_POST['name1'];
$name2 = $_POST['name2'];
$fp = fopen("data.txt","w");
if(!$fp) {
echo 'Error, the file could not be opened or there was an error creating it.';
exit;
}
fwrite($fp, "$name1"."<br/><br/>"."$name2"."\n");
fclose($fp);
}
?>Right now on the output page the data is shown using:
Code: Select all
<html>
<body>
...............
<?php
$file = fopen("data.txt", "r");
$data = fread($file, filesize("data.txt"));
fclose($file);
echo $data;
?>
...................
</body>
</html>