I have the code to a simple form page. It writes to a file and loads the content with include() but it doesn't work. Any of you could tell me where am I mistaken?
Sorry for the lack of details. :(
The code is:
<!DOCTYPE html>
<?php
if (isset($_POST) && isset($_POST['msg'])) {
$msgfile= 'msg.html';
$msg = $_POST['msg'];
$msgdetails = '<p><span>'. date("F j, Y, g:i a") .'</span>: '. $msg .'<br>\n';
$fp = fopen($msgfile, "a");
fwrite($fp, $msgdetails);
fclose($fp);
}
?>
<form method="post" action="#">
<table>
<tr><td><h3>Messages</h3></td></tr>
<tr>
<td>
<input type="text" id="msg">
<input type="submit" value="Add message!">
</td>
</tr>
<tr><td><?php include('msg.html'); ?></td></tr>
</table>
</form>
Well the error was in the , the NAME param was missing (as mentioned below). Thank you! :)
Put a name field in
<input type="text" id="msg" name="msg" />
rest of your code works fine. $_POST['msg'] reads the submitted name not the ID