Text and PHP files: How do I automatically display the message I just sent via POST on the same page?
here is my code:
<html>
<head>
<title>mboard</title>
</head>
<body>
<?php
$myfile = fopen("mboard.txt", "a+") or die("Unable to open file!");
if (filesize("mboard.txt") > 0) {
echo fread($myfile,filesize("mboard.txt"));
} else {
echo "empty file!";
}
if (!empty($_POST)) {
$txt= $_POST["text-mboard"];
fwrite($myfile, $txt);
echo fread($myfile,filesize("mboard.txt"));
};
if ($_POST) {
echo fread($myfile,filesize("mboard.txt"));
};
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="text-mboard">
</form>
<?php fclose($myfile); ?>
</body>
</html>