Shoutbox help!
- TheDayIsMine
- Novice


- Joined: Aug 18, 2008
- Posts: 22
- Status: Offline
Hello everyone, I followed THIS (click) tutorial on creating shoutbox's. After uploading the stuff, I added some css to make it look a bit prettier, and I need help with a few things regarding php and javascript- (I'm not very php / javascript smart).
I want the page to refresh every 3-5 seconds, so I tried the
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
This is the shout section php code:
I want the page to refresh every 3-5 seconds, so I tried the
Code: [ Select ]
<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
This is the shout section php code:
Code: [ Select ]
<?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="3px" cellpadding="0" class="table">
<tr>
<td class="formb">
';
$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';
setcookie('dataCookie', $name, time()+(60*60*24*365));
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);
$userCookie = $_COOKIE['dataCookie'];
if ($userCookie == '') { $userCookie = 'Anonymous'; }
?>
<div align="center">
<form name="shout" method="post" action="shout.php" class="form">
<tr><td class="formb">
<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="<?= $userCookie?>" class="input"><br>
</tr></td><tr><td class="formb">
<span class="headers">Message:</span> <br><input name="message" type="text" id="message" size="25" class="input"><br>
</tr></td><tr><td class="formb">
<input name="shout" type="submit" id="shout" value="Post!" class="submit">
</tr></td>
</div>
</form>
</table>
</div>
<div class="footer">
<a href="emotes.htm" target="page" onClick="window.open('','page','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=350,height=410,left=50,top=50,titlebar=yes')">
Show Emotes</a> |
</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>
// 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="3px" cellpadding="0" class="table">
<tr>
<td class="formb">
';
$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';
setcookie('dataCookie', $name, time()+(60*60*24*365));
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);
$userCookie = $_COOKIE['dataCookie'];
if ($userCookie == '') { $userCookie = 'Anonymous'; }
?>
<div align="center">
<form name="shout" method="post" action="shout.php" class="form">
<tr><td class="formb">
<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="<?= $userCookie?>" class="input"><br>
</tr></td><tr><td class="formb">
<span class="headers">Message:</span> <br><input name="message" type="text" id="message" size="25" class="input"><br>
</tr></td><tr><td class="formb">
<input name="shout" type="submit" id="shout" value="Post!" class="submit">
</tr></td>
</div>
</form>
</table>
</div>
<div class="footer">
<a href="emotes.htm" target="page" onClick="window.open('','page','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=350,height=410,left=50,top=50,titlebar=yes')">
Show Emotes</a> |
</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>
- <?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="3px" cellpadding="0" class="table">
- <tr>
- <td class="formb">
- ';
- $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';
- setcookie('dataCookie', $name, time()+(60*60*24*365));
- 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);
- $userCookie = $_COOKIE['dataCookie'];
- if ($userCookie == '') { $userCookie = 'Anonymous'; }
- ?>
- <div align="center">
- <form name="shout" method="post" action="shout.php" class="form">
- <tr><td class="formb">
- <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="<?= $userCookie?>" class="input"><br>
- </tr></td><tr><td class="formb">
- <span class="headers">Message:</span> <br><input name="message" type="text" id="message" size="25" class="input"><br>
- </tr></td><tr><td class="formb">
- <input name="shout" type="submit" id="shout" value="Post!" class="submit">
- </tr></td>
- </div>
- </form>
- </table>
- </div>
- <div class="footer">
- <a href="emotes.htm" target="page" onClick="window.open('','page','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=350,height=410,left=50,top=50,titlebar=yes')">
- Show Emotes</a> |
- </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>
- Anonymous
- Bot


- Joined: 25 Feb 2008
- Posts: ?
- Loc: Ozzuland
- Status: Online
December 28th, 2008, 9:08 pm
- alex89
- Bronze Member


- Joined: Jul 18, 2008
- Posts: 239
- Loc: Western Australia
- Status: Offline
- alex89
- Bronze Member


- Joined: Jul 18, 2008
- Posts: 239
- Loc: Western Australia
- Status: Offline
Page 1 of 1
To Reply to this topic you need to LOGIN or REGISTER. It is free.
Post Information
- Total Posts in this topic: 5 posts
- Users browsing this forum: No registered users and 186 guests
- You cannot post new topics in this forum
- You cannot reply to topics in this forum
- You cannot edit your posts in this forum
- You cannot delete your posts in this forum
- You cannot post attachments in this forum
