Web Hosting Deals Holiday Logo Design Webcam Chat Website Header Templates Register domain Search Engine Optimisation Web Hosting
Go Back   Talk Mania Forum > Tutorials > PHP / Perl / Java / JavaScript / CGI Tutorials

PHP / Perl / Java / JavaScript / CGI Tutorials PHP / Perl / Java / JavaScript / CGI Tutorials Please do not use this Forum to advertise your site or to link to tutorials.

 Image
Buy Sell Downloads

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-09-2007, 07:39 PM
Junior Member
 
Join Date: Feb 2007
Posts: 8
JinxHacker is on a distinguished road
Shout Box Script

Provided by www.dontplaywithyourself.com

Shoutbox
Shoutbox



Shoutboxes have become a popular way to leave messages at a site.

If you don't know what a ShoutBox is, you can check one out at Deskmod. They're a neat way to let the visitor interact with your website without the hassle of a guestbook. Making your own shoutbox at first might seem hard, but its simple and easy to make. You can see my code that I worked on and made sure worked by right clicking and saving shoutbox.txt. In fact, the one for this tutorial is only 35 lines total. Make a new file and save it as shoutbox.php and put all of the code on this tutorial in the body. Making a shoutbox can all be done with one file, specifically three steps, and you have to work backwards to have it function. First, you must make the submit action, which uploads the name and comments to the mySQL database. Secondly, you must have the display action which displays the comments. Finally, you need the form where the people can add the comments.

Before anything else though, you must make the mySQL database. I decided to add 4 fields to the database: id, name, message, and time. I called the table 'shoutbox' and the database 'news'. You can copy paste this code inside your mySQL database using a program such as PHPMyAdmin, or (type it in by hand if you feel so Here is the mySQL code I used: CREATE TABLE `shoutbox` (
`id` int(11) NOT NULL auto_increment,
`name` text NOT NULL,
`message` longtext NOT NULL,
`time` text NOT NULL,
PRIMARY KEY (`id`)
) TYPE=MyISAM;



The rest of the code from now down can all be placed on one single page. Here's what we need to do for the first step, for the submit action.

1. First off, connect to the database.
2. If submit is hit, then get the day and time to be stored on the database. You can check out the date function to gain insight on what all we're saving in there.
3. Insert the values of the id, name, comments, and time to the database.

Here it is in PHP: <?
//the host, name, and password for your mysql
mysql_connect("localhost","username","password");

//select the database
mysql_select_db("news");

if($submit)
{
//use the PHP date function for the time
$time=date("h:ia d/j/y");

// inserting it into the shoutbox table which we made in the mysql statements before
$result=MYSQL_QUERY("INSERT INTO shoutbox (id,name,message,time)".
"VALUES ('NULL','$name', '$message','$time')");
}
?>

The second part of the Shoutbox is to display all the comments which other people have written. We can use a simple while loop to get all the rows from the mySQL Database:

1. Select the last five messages posted from the shourbox table.
2. Run the while loop while it keeps getting an row.
3. Define each variable from the database and echo it out.

Here it is in PHP: <?
//returning the last 5 messages
$result = mysql_query("select * from shoutbox order by id desc limit 5");

//the while loop
while($r=mysql_fetch_array($result))
{
//getting each variable from the table
$time=$r["time"];
$id=$r["id"];
$message=$r["message"];
$name=$r["name"];
?>
<? echo $time ?><br>
<? echo $name ?><br>
<? echo $message ?><br>
<? } ?>

Finally, you have to write the form action for the shoutbox to load for folks to post. Its not too hard, and sort of self explanatory: <form action="<? echo $php_self ?>" method="post">
<INPUT TYPE='TEXT' value='name' NAME='name' SIZE=30 maxlength='100'><br>
<INPUT TYPE='TEXT' value='message' NAME='message' SIZE=30 maxlength='100'>
<input type="submit" name="submit" value="submit">
</form>

Reply With Quote
  #2 (permalink)  
Old 04-10-2007, 12:54 AM
Junior Member
 
Join Date: Apr 2007
Posts: 3
ayah is on a distinguished road
nice script!
Reply With Quote
  #3 (permalink)  
Old 04-10-2007, 06:54 AM
Base's Avatar
Senior Member
 
Join Date: Mar 2007
Location: North Yorkshire, UK
Posts: 121
Base is on a distinguished road
Send a message via MSN to Base Send a message via Skype™ to Base
Generally the tutorial was ok.

But there are a few points i would like to pick you up on, and i don't mean to be rude.

1.) Don't copy tutorials from other websites.

2.) Actually explain your code, rather than explaining what it does.

Example:

CREATE TABLE `shoutbox` (
`id` int(11) NOT NULL auto_increment,
`name` text NOT NULL,
`message` longtext NOT NULL,
`time` text NOT NULL,
PRIMARY KEY (`id`)
) TYPE=MyISAM;

In literal terms it does the following:

"Creates the table called shoutbox, with the following fields.

ID with has to be an integer (number) which is not null, (null meaning that there is no known value) and its auto increment, so every time somthing is inserted and the ID filed is called, then it adds a number to the auto increment.
Create a collum called name which is text and again not null
Creates a collum message which again is not null.

Creates a table called time, which is not null."

3.) either type this:

[PHP*]YOUR CODE HERE[/PHP*]

(Remove the stars)

or press the PHP or # buttons on the top left of this window.

4.) Don't copy and paste code especially from another website. Because it could not actually be working.

5.) Create your OWN tutorials. Don't post other peoples.

If you follow the above, then we'll get along just great!

But thankyou for sharing the code.

Yours most sincerely

Thomas Gray
__________________
http://www.pointserv.co.uk/gfx/deal_..._pointserv.png
PointServ.co.uk - One of the UK's cheapest webhosting companies.
Reply With Quote
  #4 (permalink)  
Old 04-10-2007, 06:55 PM
Junior Member
 
Join Date: Feb 2007
Posts: 8
JinxHacker is on a distinguished road
this is my site

that site is my site. So i geuss i can take anything thats on it.
__________________
www.dontplaywithyourself.com
Reply With Quote
  #5 (permalink)  
Old 04-10-2007, 09:50 PM
Base's Avatar
Senior Member
 
Join Date: Mar 2007
Location: North Yorkshire, UK
Posts: 121
Base is on a distinguished road
Send a message via MSN to Base Send a message via Skype™ to Base
Ok, but your explanation still leaves allot to be desired.

Base
__________________
http://www.pointserv.co.uk/gfx/deal_..._pointserv.png
PointServ.co.uk - One of the UK's cheapest webhosting companies.
Reply With Quote
  #6 (permalink)  
Old 04-11-2007, 07:56 AM
Junior Member
 
Join Date: Mar 2007
Posts: 25
Willyke is on a distinguished road
Quote:
Originally Posted by JinxHacker View Post
that site is my site. So i geuss i can take anything thats on it.
Depends if you have putten it on your site or your guests xD, but like Base said, more explanation would come in handy for the new php-ers in our mids.
Reply With Quote
  #7 (permalink)  
Old 04-17-2007, 11:06 AM
Junior Member
 
Join Date: Apr 2007
Posts: 3
Csiga is on a distinguished road
Nice tutorial.
It's really easy script :P
Reply With Quote
  #8 (permalink)  
Old 04-25-2007, 01:51 AM
Junior Member
 
Join Date: Apr 2007
Posts: 4
iswm is on a distinguished road
thats a nice script but u should try m aking one with ajax
Reply With Quote
  #9 (permalink)  
Old 04-25-2007, 07:26 PM
Junior Member
 
Join Date: Apr 2007
Posts: 4
eduncan50 is on a distinguished road
Talking thanks

I think Igoing to try this.
Reply With Quote
  #10 (permalink)  
Old 04-26-2007, 12:07 AM
Junior Member
 
Join Date: Apr 2007
Posts: 3
av1nnik415 is on a distinguished road
very nice i like it.

Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT +2. The time now is 01:29 AM.


Fake ID

Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC8
Forums Copyright © Talk-Mania.com