I want the page to refresh every 3-5 seconds, so I tried the
<meta http-equiv="refresh" content="5">but I don't want whatever the person was typing in the 'message' section to disappear on refresh. I just want the table td holding the already posted shouts to refresh but not the actual form- I searched and searched google for this and all I got is that it's possible with AJAX- but I didn't find a clear- working code
I also want the 'name' to be remembered in a javascript or php cookie, but I can't get any of the codes I searched for to work with the script =/
I hope I'm not asking for too much- If you know how to resolve ANY of the above two issues please help me out =/
the currently revised shout.php script is
<?php
// calling session_start() the function which starts our authentication session
session_start();
// connecting to mysql server
$l = mysql_connect ( "localhost" , "Admin" , "shoutbox" ) or die("Error connecting:<BR><BR>".mysql_error());
mysql_select_db( "evergre7_shoutbox" ) 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" cellspacing="3" cellpadding="0" class="table">
<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="dash">|</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>
';
} // function getshouts
// our processing if control statement
if ( isset ( $_POST['shout'] ) )
{
$name = addslashes($_POST['name']);
$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);
?>
<div align="center">
<form name="shout" method="post" action="shout.php" class="form">
<tr><td>
<span class="headers">name:</span> <br><input name="name" type="text" id="name" size="25" maxlength="10" onfocus="this.select()" onblur="this.value=!this.value?'Anonymous:':this.value;" value="Anonymous" class="input"><br>
</tr></td><tr><td>
<span class="headers">Message:</span> <br><input name="message" type="text" id="message" size="25" class="input"><br>
</tr></td><tr><td>
<input name="shout" type="submit" id="shout" value="Post!" class="submit">
</tr></td>
</div>
</form>
</table>
</div>
<link href="shoutbox.css" rel="stylesheet" type="text/css">
<body>
<script type="text/javascript">
window.onload = function () {
// focus on the input field for easy access...
var input = document.getElementById ('message');
input.focus ();
// ...but if someone wishes to go back in their history, let them!
document.onkeydown = function (e) {
if (!e) {
var e = window.event;
}
if (e.keyCode === 8 && !input.value) {
history.back();
}
};
};
</script>


Sign In
Create Account

Back to top









