<?php
// calling session_start() the function which starts our authentication session
session_start();
// connecting to mysql server
$l = mysql_connect ( "localhost" , "username" , "password" ) or die("Error connecting:<BR><BR>".mysql_error());
mysql_select_db( "DBNAME" ) or die("Error getting db:<BR><BR>".mysql_error());
// defining getShouts() which is our function that gets all of our shouts
function getShouts()
{
echo '<div align="center">
<table width="150" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
';
$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">'.$name.'</span> - <span class="shout">'.$shout.'</span></p>';
} else {
echo '<p><span class="author"><a href="'.$contact.'" target="_blank">'.$name.'</a></span> - <span class="shout">'.$shout.'</span></p>';
} // if empty contact
} // while row mysqlfetcharray query
echo '<br><br>';
echo '
</td>
</tr>
<tr>
<td height="10"> </td>
<form name="shout" method="post" action="shout.php">
<div align="center">
<input name="name" type="text" id="name" value="Name" size="25" maxlength="10"><br>
<input name="contact" type="text" id="contact" value="http://" size="25"><br>
<input name="message" type="text" id="message" value="Message" size="25"><br>
<input name="shout" type="submit" id="shout" value="Shout!">
</div>
</form>
</td>
</tr>
</table>
</div>
';
} // function getshouts
// our processing if control statement
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");
// if they weren't even referred from the form, show error dialog and redirect
} // if isset post shout
/* STARTING THE MAIN SCRIPT NOW */
// starting the table
//displaying the shouts
getShouts();
mysql_close($l);
?>
Shoutbox Interface?
Started by nygorn, Apr 07 2008 05:24 AM
2 replies to this topic
#1
Posted 07 April 2008 - 05:24 AM
I've found a shoutbox tutorial that i followed and got it to work after a while. Only problem is that the forms are on the top of the messages, i want it under. The last 2 days i've tried to change the code but no sucess, can anyone that got a tiny bit of more experience help me out ?
#2
Posted 07 April 2008 - 07:43 PM
From the looks of the code, the textarea (form) is under it :-\
#3
Posted 09 April 2008 - 04:28 AM
Well, nevermind! I solved it. The mess of Div and Table tags messed it up!
But now the smileys wont work ;S the mysql is right, the url to smileys is right, but when i do the command for example
it gets : huh : without the spaces
But now the smileys wont work ;S the mysql is right, the url to smileys is right, but when i do the command for example
Edited by nygorn, 09 April 2008 - 04:50 AM.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users
