<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Message Boards</title>
</head>
<body>
<?php
//connect to a database
mysql_connect ("localhost", "
username", "
password") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("
database name") or die ('I cannot connect to the database because: ' . mysql_error());
//Get current date and set as a variable
$dateadd=date("j of F Y, \a\\t g.i a", time());
//If someone wants to delete a message then this is what the command getrs sent to
if($mode=="remove") {
mysql_query("DELETE FROM messageboards WHERE number = $ID");
}
//Saves what the user has inputed to a form into the database along with the date
if($mode=="add") {
mysql_query("INSERT INTO messageboards (name, date, title, message)
VALUES ('$_POST[nameadd]', '$dateadd', '$_POST[titleadd]', '<pre>$_POST[messageadd]</pre>')")
or die ('I cannot add message because: ' . mysql_error()); }
//Get all the table information and arrange newest to oldest
$result = mysql_query("SELECT * FROM messageboards ORDER BY number DESC");
//Make each column an array
while($row = mysql_fetch_array($result)) {
$number[]= $row['number'];
$n_name[]= $row['name'];
$date[]= $row['date'];
$title[]= $row['title'];
$message[]= $row['message']; }
//start making a table
echo "<table border='1' width='500px'>";
//display each message from the database in this table
for ($i = 0; $i < sizeof($number); $i++) {
echo "<tr><td>" . $n_name[$i] . "</td></tr>";
echo "<tr><td>" . $date[$i] . "</td></tr>";
echo "<tr><td><strong>" . $title[$i] . "</strong></td></tr>";
echo "<tr><td>" . $message[$i] . "</td></tr>";
echo "<tr><td><a href=\"$PHP_SELF?ID=$number[$i]&mode=remove\">Delete Message</a></td>";
echo "<tr><td><br /><br /></td></tr>"; }
echo "</table>";
//The form from which someone can post a message
echo "
<form method='POST' action=\"$PHP_SELF?ID=$number[$i]&mode=add\">
<p><strong>Name: </strong><br /><input type='text' size='50' name='nameadd' /><br />
<strong>Message Title: </strong><br /><input type='text' size='50' name='titleadd' /><br />
<strong>Message: </strong><br /><textarea cols='70' rows='20' name='messageadd' wrap='virtual'></textarea><br />
<input type='submit' value='Add Message' /></p><br />
</form>";
?>
</body>
</html>