Welcome, Guest

Please login or register

TUTORIALS SUBMENU

PHOTOSHOP    FLASH    ILLUSTRATOR    BLENDER    CINEMA 4D    WEB-CODING    [SUBMIT]

Related Links

The Complete Shoutbox Tutorial

pages (3): [1] 2 3


Now that you know the basics of PHP and MySQL connectivity, its time to add a little interaction with this cool little applet that allows your users to leave short messages - a system commonly referred to as a shoutbox.  In this tutorial I will detail everything you need to know about making your very own shoutbox, right down from the HTML form, to the smilie emoticon configuration and anti-spam measures.

You will need the following to be able to complete this tutorial:

  • A PHP enabled webserver.
  • A mySQL database.
  • An hour of free time.
  • Sessions enabled.
  • File uploads enabled.

Getting Started
As a first step we should think about the layout and size of our shoutbox - 150px wide and 500px high is just about right.  I'll refrain from using an iframe in my example because I really don't like them.   We'll also give the shoutbox a 10 entry display limit (i.e. the latest 10 entries will display - the rest will be hidden).   With these considerations aside, we can start by setting up two mySQL tables in our database: shouts and smilies.

shouts has 4 fields:
- id, int(11), auto_increment, PRIMARY
- Name, TEXT
- Shout, TEXT

- Contact, TEXT

smilies has 4 fields:
- id, int(11, auto_increment, PRIMARY
- Symbol, VARCHAR(4)
- URL, TEXT
- Alt, TEXT

If you don't know what this formatting means, int is the type of field, the number in brackets is the size, auto_increment is a feature, and PRIMARY is a type, defining it as unique. Text is a field type, as is VARCHAR, and the number in brackets again is the field length.

With these tables in place you should create your shoutbox directory, and then a subdirectory off it called smilies. CHMOD it to 777 (i.e. all permissions). If you don't know what this means or can't manage it, contact me using the information at the end of this tutorial.

Breakdown of shout.php
There are two pages in our script, shout.php and admin.php - both of which are downloadable here. You can, of course, just grab the scripts and get the shoutbox working without reading the rest of this tutorial, but that would be no fun at all.   For all those people actually interested in learning the workings of this script, though, I'll first break down shout.php and I’ll explain how it works.

// calling session_start() the function which starts our authentication session
session_start();

// connecting to mysql server
$l = mysql_connect ( "localhost" , "user" , "pass" ) or die("Error connecting:<BR><BR>".mysql_error());
mysql_select_db( "user" ) or die("Error getting db:<BR><BR>".mysql_error());

This is the main building block of both scripts. It starts all session registering or management with session_start(), and then selects and connects to our database. You should, of course, edit the mySQL connectivity lines to reflect your own mySQL settings.

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">&nbsp;</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

This is probably the most important function for the whole script, as it processes and displays the shouts. First of all, this function selects the newest 10 shouts by ordering them by id in descending order. It then cycles through and displays the records. The author and message tags have SPAN classes around them, but I haven’t defined the applicable CSS tags. If you wish to define them, go to line 87 of shout.php where it says /* STARTING THE MAIN SCRIPT NOW */, and add the following code below it:

echo ‘<link href="yourfile.css" rel="stylesheet" type="text/css">’;

In yourfile.css add two classes: author and shout, which are self explanatory as to where they will appear. This will be very useful when you want to format your shouts cohesively.

Now, back to our function. In addition to what I said earlier, it removes the slashes from our database results (because we added some when we posted them), and it checks to see whether or not the contact variable was empty when the user posted. If the user did not specify any contact information, a plain name is displayed without a hyperlink.  If the opposite happens, their name is enclosed within a nice big hyperlink instead.

- Tutorial written by Scrowler

Pages (3): [1] 2 3 Next>
Automatic Translations: Translate Into French Translate Into German Translate Into Italian Translate Into Spanish Translate Into Portuguese

Last 5 User Comments

User:  slepage95 (#63101)
Date: Mon Jun 07, 2010. 01:06:57

Post #4 of 4

Good tutorial^^ Just have one question, is there a way we can add sound when a message is received? Thanks

Reply to this post


User:  s3xyglass3s (#48812)
Date: Mon Mar 17, 2008. 14:07:43

Post #3 of 4

great work :D

I just have one question; how can you separate the action, that you have in the .fla file, and have a separate .as file?

I always get stuck there, and I have to make a shoutbox for school, with a separate .as file..

is it hard? can you show me?

Thnx

Steffy

Reply to this post


User:  Tamlin (#34751)
Date: Wed Nov 22, 2006. 00:25:26

Post #2 of 4

Quote from flores741;34750:
Nice work, but thought I might point out smilies is actually SMILES :D


If you mean these things: :) :) :lol: :ciao:
I think you'll find that in 99.99999% of the web they are called Smilies, not Smiles. :nyanya:

Short for "Smiley Face", I assume.

Reply to this post


User:  flores741 (#34750)
Date: Wed Nov 22, 2006. 00:04:43

Post #1 of 4

Nice work, but thought I might point out smilies is actually SMILES :D

Reply to this post


--- View Entire Thread ---
Featured Tutorialsmore

Meteor Tutorial - ...
Meteor Tutorial - ...
- Maxon Cinema 4D -
Planetary Rings
Planetary Rings
- Adobe Photoshop -
Remote Rollovers
Remote Rollovers
- Adobe Photoshop -
Rock Textures
Rock Textures
- Adobe Photoshop -
Membership

Username:
Password:  
Remember Me

Lost Password? || Register

Related Links

Special Options
Download Source File
Printer Friendly Version
Forum Threads

Fire text effect in 3ds max
Author: heartscool
Posted: Jul 24th, 1:56pm
Activity: 0 replies, 0 views
Where did everyone go!?!
Author: LemonTree
Posted: Jul 22nd, 12:15am
Activity: 6 replies, 0 views
Protecting Email Addresses from Spammers in HTML
Author: LemonTree
Posted: Jul 22nd, 12:13am
Activity: 0 replies, 0 views
3ds max wireframe render ?
Author: heartscool
Posted: Jul 20th, 2:51pm
Activity: 0 replies, 0 views
Site issue
Author: Jormi_Boced
Posted: Jul 07th, 8:40pm
Activity: 11 replies, 0 views
3D Studio Max Keyboard shortcuts
Author: heartscool
Posted: Jul 07th, 6:48pm
Activity: 0 replies, 0 views
Regarding Vector/Custom Shapes in Photoshop
Author: Phoenix Wynde
Posted: Jul 06th, 1:39pm
Activity: 0 replies, 0 views
forgot a songs name
Author: unleash
Posted: Jun 30th, 10:37pm
Activity: 8 replies, 0 views
Tutorials Upload System Active
Author: Man1c M0g
Posted: Jun 28th, 11:53am
Activity: 0 replies, 0 views
Brushes Uploaded Here...
Author: Jasmine
Posted: Jun 23rd, 5:55pm
Activity: 1 replies, 0 views
Uploading Resources: Alternative Method?
Author: Jasmine
Posted: Jun 21st, 10:31pm
Activity: 1 replies, 0 views
Public Vote on Brush Contest Entries...
Author: Jasmine
Posted: Jun 17th, 12:25am
Activity: 0 replies, 0 views
Forum Threads

--- Site Resources ---
Total Tutorials:212
Total Downloads:    438
Total Fonts:    4673