PHP Shoutbox

Mani5

New Member
Messages
946
Reaction score
0
Points
0
Source: http://www.media-ops.com

My first ever tutorial! (php wise...). I first made this for www.re-mi.be, which is currently down, and then updated it and now i use it on my personal site www.r.dsx3.com :p. Its a basic script, but if you would like a shout box then it is perfect :p.

There will be 5 parts to this tutorial:
>Making the SQL Table
>Creating the Form
>Creating the Action
>Creating the Output
>Creating the index

lets get started :p.

Open up Phpmyadmin, or whatever you use for sql. Run this query
Code:
CREATE TABLE `shout` (
`id` INT NOT NULL AUTO_INCREMENT ,
`name` TEXT NOT NULL ,
`message` TEXT( 100 ) NOT NULL ,
PRIMARY KEY ( `id` )
);​


You can change the 100 (in the paranthesis) to however many characters you would like to limit the peoples messages to.

What the query does, for people who dont get it: It creates a table called shout, and makes three rows. ID, name, and message. The name and message are inputted by the user, and the id automaticaly increases each time a person "shouts".

now create a directory called shout. You dont want things to get all ugly and disorganized :p.

Now we are going to create the form. Name this add.php
Code:
<form name="addform" method="post" action="shoutbox/action.php">
<table width="150" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><b>Name:</b></td>
<td><input type="text" id="name" name="name"></td>
</tr>
<tr>
<td><b>Msg:</b></td>
<td><input type="text" id="message" name="message"></td>
</tr>
</table>
<table width="150" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center"><input type="submit" name="shout" title="shout" value="shout"></td>
</tr>
</table>
</form>​


I put it in the table so i could control the alignment :p. You could/should add some css, to make the inputs look pretty :p, because the default ones arent so.

Now we are going to make the action file. Name this action.php <-- :p

Code:
<?php

//fill it out according to the sql table you set up
$username="Username";
$password="Password";
$database="Database";
$table="shout";

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query="INSERT INTO $table (id, name, message) values ('$id','$name','$message')";
$result=mysql_query($query);
echo "Succsesfully Shouted. <a href=\"http://www.yoursite.com\">Return</a>";
?>​


Make sure, when you change the href, to keep the last \ there :p. Change the username pswrd and databae names also.
 

motogawa

Member
Messages
306
Reaction score
0
Points
16
He wants to know if you have like a display of the shoutbox in work.
 

Mani5

New Member
Messages
946
Reaction score
0
Points
0
no I dont sorry.......{embarresed}

but I hav an easier solution..go to MYSHOUTBOX.com and register and configure smileys and everythin then when u r all done, click da Code generator thing..and Voila! u will get a code u can put on ur PHP/HTML site and its so easy set up...

ENJOY

P.S. they giv previews...
 
Top