Flat File Text Database System CMS Edit Content Tutorial
In this 2 part lesson series we demonstrate using .txt Flat File Database systems as an alternative to MySQL, XML, or other database systems. In this final part you will learn how to allow a user or client to change the data from smart easy web forms. Many people do not have tech knowledge and do not like going on the server to alter a CMS file. You must make forms to alter the data if you wish to have happier higher paying clients.
<?php
$myfile = "file1.txt";
if (isset($_POST['ta'])) {
$newData = nl2br(htmlspecialchars($_POST['ta']));
$handle = fopen($myfile, "w");
fwrite($handle, $newData);
fclose($handle);
}
// ----------------------------
if (file_exists($myfile)) {
$myData = file_get_contents($myfile);
}
?>
Hello user, use this form to edit the writing on your live website
<form action="file.php" method="post">
<textarea name="ta" cols="64" rows="10">
<?php echo str_replace("<br>","",$myData); ?>
</textarea>
<br><br>
<input name="myBtn" type="submit" />
</form>
<br><br>
<?php echo $myData; ?>