Jump to content
xisto Community
Sign in to follow this  
iGuest

Shoutbox tutorial!!!

Recommended Posts

Here's my tutorial of making a shoutbox.

1. First of all we need to create the MySQL database (this is the important part):

CREATE TABLE `shoutbox` ( `id` INT(12) NOT NULL AUTO_INCREMENT, `username` VARCHAR(25) NOT NULL, `email` VARCHAR(25) NOT NULL, `message` TEXT NOT NULL, `date` VARCHAR(15) NOT NULL, `ip` VARCHAR(25) NOT NULL , PRIMARY KEY (`id`))

All the details (the message, and stuff) are going to these tables.

2. Now we will create the page called connect.php.
With this page the shoutbox will connect to the database and send the
message you wrote and all the other stuff.

<?php $co_host = "localhost"; // sql database host $co_name = "username"; // username $co_pw = "password"; // password $co_db = "database name"; // database name you got access to mysql_connect($co_host,$co_name,$co_pw) or die(mysql_error()); mysql_select_db($co_db) or die(mysql_error()); ?>

3. And now, finally, the last part: writing the shoutbox itself.

<html> <head> <title>Shoutbox!</title> <style type="text/css"> <!-- .message { color: #000000; font-family: Verdana; font-size: 10px;} .username { color: #FF9900 font-family: Verdana; font-size: 10px; font-weight: bold} .date { color: #707070; font-family: Verdana; font-size: 9px;} .forms { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10 px; color: #6CA05A; text-decoration: none; background-color: #CCCCCC; border-color: #6CA05A; border-style: solid; border: 1px} .submit { background-color: #CCCCCC; border-color: #6CA05A; color: #2A343C; font-family: Verdana; font-size: 10px; border-style: solid; border 1 px;} --> </style> </head> <body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" style="padding: 2px"> <?php // If submitted if($_POST['submit']) { // Verify if the fields were filled. if(!$_POST['username']) { echo 'Error, You need to post your Username!'; die; } if(!$_POST['email']) { echo 'Error, You need to post your Email!'; die; } if(!$_POST['message']) { echo 'Error, You need to post a Message!'; die; } // Date format $date = date("d/m/y"); // http://http://de2.php.net/manual/de/function.date.php // Assign variables of the forms $username = $_POST['username']; $email = $_POST['email']; $message = $_POST['message']; $ip = $_SERVER['REMOTE_ADDR']; // Connect to the database include('connect.php'); // Insert the info in the shoutbox table. $query = "INSERT INTO shoutbox (username, email, message, date, ip) VALUES ('$username','$email','$message','$date','$ip')"; mysql_query($query); // close connection mysql_close(); // Show message to let them return to the shoutbox ?> <div align="center">Thank you for submitting.<br> Return to the <a href="shoutbox.php">shoutbox</a>! <?php // If NOT submitted } else { // connect to the database include('connect.php'); $query = "SELECT * FROM shoutbox ORDER BY id DESC LIMIT 10"; $result = mysql_query($query); // Create a table ?> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <? // Run a While loop for the rows while($c = mysql_fetch_array($result)) { ?> <tr> <td><a href="mailto:<? echo $c[email] ?>"> <? echo $c[author] ?></a> says: <div align="justify"><? echo $c[message] ?></div> </td> </tr> <tr><td>on <? echo $c[date] ?> <hr noshade="noshade" size="1" style="border-style: dashed" color="#000000" /></td></tr> <? } ?> </table> <form method="post" action="shoutbox.php"> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td>Username :</td> <td><input type="text" name="username" class="forms"></td> </tr> <tr> <td>Email :</td> <td><input type="text" name="email" class="forms"></td> </tr> <tr> <td>Message :</td> <td><input type="text" name="message" class="forms"></td> </tr> <tr> <td colspan="2"><input type="submit" name="submit" value="Speak!" class="subtmit"></td> </tr> </table> </form> <? } mysql_close(); ?> </body> </html>

Save it and call it shoutbox.php.

if you have any questions don't be shy and ask me here: odirima@walla.co.il

Share this post


Link to post
Share on other sites

odirima you have a few areas with your script!

 

heres the changes:

 

1. $c[author] was not a vaild value change to $c['username']

 

2. change:

$c to $c['email']

$c[message] to $c['message']

$c [date] to $c['date']

 

As you for got to wrap email, message and date with two '

 

hay man good tutorial! but a few errors! which I have corrected!

Share this post


Link to post
Share on other sites

Its working so far, thanks but i dont know how to alter the style of text that shows on the shoutbox, like colour and font. Can anyone help? :D thanks

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.