Most Simple Forum Script
Posted: Sat Oct 01, 2011 7:41 am
Hope this is useful!
Just mod the obvious bits!
for help email 08jpurcell@gmail.com
Just mod the obvious bits!
for help email 08jpurcell@gmail.com
Code: Select all
<?php
/**
* Create the table in your MySQL database:
*
* CREATE TABLE Forum (
* id int(10) NOT NULL auto_increment,
* Username varchar(50) NOT NULL,
* Post varchar(255) NOT NULL,
* PostTitle varchar(255) NOT NULL,
* date timestamp(14) NOT NULL,
* PRIMARY KEY (id)
* )
*
* Change the database login settings to your own
*
* The script is now ready to run
*/
$e = $_GET['Error'];
$p = $_GET['Post'];
// Change these to your own database settings
$host = "TYPE HOST HERE";
$user = "TYPE DB USER HERE";
$pass = "TYPE DB PASSWORD HERE";
$db = "TYPE DB NAME HERE";
$thisfile = "?page=Forum";
mysql_connect($host, $user, $pass) OR die ("Could not connect to the server.");
mysql_select_db($db) OR die("Could not connect to the database.");
$title = stripslashes($_POST['txtName']);
$message = stripslashes($_POST['txtMessage']);
if (!isset($_POST['txtName'])) {
$query = "SELECT id, Username, Post, PostTitle, DATE_FORMAT(date, '%D %M, %Y @ %H:%i') as newdate FROM Forum ORDER BY id DESC";
$result = mysql_query($query);
while ($row = mysql_fetch_object($result)) {
if ($p == "$row->id") {
echo "$row->Post";
echo "<br><br><a href='$thisfile'>Back</a>";
die();
}
?>
<p><a href='<?php echo "$thisfile&Post=$row->id"; ?>'><strong><?php echo $row->PostTitle; ?></strong>
<br />Posted by <?php echo $row->Username; ?> on <?php echo $row->newdate; ?></a></p>
<?php
}
?>
<p>Post a message</p>
<form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
<?
if ($e == "1") {
echo "<font color='red'><h2>No Title Set!</h2></font>";
}
if ($e == "2") {
echo "<font color='red'><h2>No Content Set!</h2></font>";
}
if ($e == "1,2") {
echo "<font color='red'><h2>No Title & Content Set!</h2></font>";
}
?>
<p><label for="txtName">Title:</label><br />
<input type="text" title="Enter your name" name="txtName" /></p>
<p><label for="txtMessage">Your message:</label><br />
<textarea title="Enter your message" name="txtMessage"></textarea></p>
<p><label title="Send your message">
<input type="submit" value="Send" /></label></p>
</form>
<?php
}
else {
// Adds the new entry to the database
$query = "INSERT INTO Forum SET Post='$message', PostTitle='$title', Username='$session->username', date=NOW()";
$result = mysql_query($query);
// Takes us back to the entries
$ref = $_SERVER['HTTP_REFERER'];
echo "<meta http-equiv='REFRESH' content='0;url=$thisfile'>";
}
?>