shoutbox.phps

<?php
 
class shoutbox {
 
var $listlimit;
var $bgcolor1;
var $bgcolor2;
 
function connect() {
mysql_connect("server", "user", "password") 
OR die ("Connection Error to Server");
mysql_select_db("shout Database") OR die("Connection Error to Database");
} 
 
function displayform() { //display the shoutbox form
echo"
<TABLE WIDTH=\"170\" BORDER=\"0\" CELLPADDING=\"4\" CELLSPACING=\"0\">
<FORM NAME=\"shout\" ACTION=\"index.php\" METHOD=\"post\">
<TBODY>
<TR>
<TD ALIGN=\"center\">
<INPUT TYPE=\"text\" VALUE=\"name\" NAME=\"shoutname\" SIZE=\"20\"><BR>
<INPUT TYPE=\"text\" VALUE=\"shout\" NAME=\"shout\" SIZE=\"20\"><BR>
<INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Shout!\"> <INPUT TYPE=\"reset\" VALUE=\"Reset\">
</TD>
</TR>
</TBODY>
</FORM>
</TABLE>\n";
} 
 
function displayshoutbox() { //displays shouts in the table up to the defined limit
echo "<p>
<TABLE WIDTH=\"170\" BORDER=\"0\" CELLPADDING=\"4\" CELLSPACING=\"0\">";
$shoutboxResult = mysql_query("SELECT * FROM myshout ORDER BY 
shoutid DESC LIMIT $this->listlimit;");
 
if ($shoutboxRow = mysql_fetch_array($shoutboxResult)) {
do {
 
$shoutid = $shoutboxRow[shoutid];
$shoutname = $shoutboxRow[shoutname];
$shoutdate = $shoutboxRow[shoutdate];
$shoutmsg = $shoutboxRow[shoutmsg];
 
$shoutmsg = wordwrap($shoutmsg, 20, "\n", 1);
$bgcolor = ($count++ % 2) ? "$this->bgcolor1" : "$this->bgcolor2";
 
echo "<TR><TD BGCOLOR=\"$bgcolor\">$shoutname: $shoutmsg<DIV ALIGN=\"right\">
$shoutdate</DIV></TD></TR>\n";
} 
while($shoutboxRow = mysql_fetch_array($shoutboxResult));
} 
else {
echo "No shouts yet";
} 
echo "</TABLE>";
} 
 
function insertshout($shoutname, $shout) { //insert data into table
$shoutname = strip_tags($shoutname);
$shout = strip_tags($shout, '<a><b><i><u>'); //strip html tags allowing only <a><b><i><u>
if (mysql_query ("INSERT INTO myshout (shoutname, shoutmsg, shoutdate) VALUES 
('$shoutname', '$shout', NOW())")) { 
echo "";
} 
else {
echo mysql_error();
} 
} 
} 
 
?>