I’m trying to make a message board with php, but when a new message is posted the page goes to add.php instead of staying at index.php.
I stores the messages from user in a text file. When there is a new message, I append the file. There are 4 file in my www directory – index.php, show.php, add.php and comments.txt.
My index.php looks like this:
<html>
<head>
<title>messages</title>
</head>
<body>
<h1>Messages</h1>
<div id="comments">
<?php include("show.php"); ?>
<?php include("add.php"); ?>
</div>
</body>
</html>
My add.php looks like this:
<?php
if (isset($_POST['cmt'])) {
$cmt = $_POST['cmt'];
$fh = fopen("comments.txt", 'a');
fwrite($fh, "B_E_G_I_N\n");
fwrite($fh, "$cmt\n");
fwrite($fh, "E_N_D\n");
fclose($fh);
}
?>
<form action="add.php" method="POST">
<input type="text" name="cmt">
<input type="submit" value="ok"/>
</form>
I know my implementation is really bad, but I really want to make it work first.
Thanks!
add
header('Location:index.php');at the end of
add.php.Also it goes to
add.phpbecause the form action says so