Jump to content

PHP & MySQL shoutbox.... archiving????


dj scousey

Recommended Posts

Hi all,

 

I have just created a shoutbox using PHP & MySQL. But what i want to do is, put a limit of 15 shouts on the box, and then anything more than that you can access by clicking Next Page/Prev Page.

 

The code i have for the box is as follows:

 

<html>
<head><title>SLR - ShoutBox</title>
<link href="default.css" rel="stylesheet" type="text/css">
<meta http-equiv="refresh" content="45">
<style type="text/css">
a:link {color: black; weight: bold;} 
a:visited {color: black; weight: bold;} 
a:active {color: black; weight: bold;} 
a:hover {color: red; weight: bold;} 								
body {background-color: #BDD8F6;} 
.txtBox {boackground-color: #ffff99;}</style></head>
<div align="left">
<table width="150" cellspacing="0" cellpadding="0" align="center" class="phpshout_table">
 <tr><td class="phpshout_table">
<table border="0" border-color="#00CCFF"><tr><td bgcolor="#3399ff" width="174"> <center><b>ShoutBox</b></center> </td></tr></table>
		<form name="shout" method="post" action="shout.php">
		  <div align="left">
			 <input name="name" type="text" id="name" value="Name" size="25" maxlength="10" class="txtBox" onclick="this.value=''">
			 <input name="contact" type="text" id="contact" value="URL/Email" size="25" class="txtBox" onclick="this.value=''">
			 <input name="message" type="text" id="message" value="Message" size="25" onclick="this.value=''">

			<font size="1px"><a href="admin.php"> Board Admin </a> <a href="javascript:this.location.reload();">Refresh</a></font>
		<input name="shout" type="submit" id="shout" value="Shout!" color="#33ccff">
		  </div>
		</form>
		</td>
	  </tr>

<?php

session_start();

$l = mysql_connect  ( "localhost" , "shoutuser" , "shoutuser" ) or die("Error connecting:<BR><BR>".mysql_error());
mysql_select_db( "shouts" ) or die("Error getting db:<BR><BR>".mysql_error());

function getShouts()
{		

$query = mysql_query("SELECT * FROM shouts ORDER BY id DESC LIMIT 10") or die(mysql_error());
while ($row = mysql_fetch_array($query) )
{

	$name = stripslashes($row['Name']);
	$contact = stripslashes($row['Contact']);
	$shout = stripslashes($row['Shout']);

	if(empty($contact))
	{

		echo '<p><span class="author"><b>'.$name.'</b></span> - <span class="shout">'.$shout.'</span></p>';

	} else {

		echo '<tr border="1" border-color="#00CCFF"><td class="phpshout_posts"><p><a href="'.$contact.'" 

target="_blank"><strong>'.$name.'</strong></a></span> - <span class="shout">'.$shout.'</span></p></td></tr>';

	}

} 
?>
</td></tr>	

	  </table>
	  </div>

<?php
} 



if ( isset ( $_POST['shout'] ) )
{

$name = addslashes($_POST['name']);
$contact = addslashes($_POST['contact']);
$message =  $_POST['message'];

if ( ( isset($name) ) && ( isset($message) ) )
{

	// getting smilie list
	$smilies = mysql_query("SELECT * FROM smilies") or die(mysql_error());
	while($get = mysql_fetch_array ($smilies))
	{

		$alt = $get['Alt'];
		$smilie = $get['URL'];

		$message = str_replace( $get['Symbol'] , '<img src="smilies/'.$smilie.'" border="0" width="15" height="15" alt="'.$alt.'">' , $message);
		$themessage = addslashes($message);

		// replacing all smilies

	}

	mysql_query("INSERT INTO shouts (Name, Contact, Shout) VALUES ( '$name' , '$contact' , '$message' )") or die(mysql_error());
	$_SESSION['has_posted'] = 'yes';
	header("Location: shout.php");

	// if required fields aren't empty, process into database

} else {

	echo '<script>alert("Some fields were not filled out!");</script>';
	header("Location: shout.php");

	// if required fields were left empty, show an error dialog

}

}/* else {

echo '<script>alert("Please follow the form to this page.");</script>';
header("Location: shout.php");



} 

/* STARTING THE MAIN SCRIPT NOW */




getShouts();


mysql_close($l);


?>
</body></html>

 

Any ideas??

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/89371-php-mysql-shoutbox-archiving/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.