Reply
Create a simple Shout box
Old 04-20-2006, 10:57 PM Create a simple Shout box
Junior Talker

Posts: 23
First We're going to Create our mysql database

CREATE TABLE `shoutbox` (
`id` int( 5 ) NOT NULL AUTO_INCREMENT ,
`name` varchar( 20 ) NOT NULL ,
`email` varchar( 30 ) NOT NULL ,
`website` varchar( 100 ) NOT NULL ,
`message` text NOT NULL ,
`ip` varchar( 40 ) NOT NULL ,
PRIMARY KEY ( `id` )
) TYPE = MYISAM


Code:
<?php 


$limit = 20; # this is the limit of how many shouts you want posted on the shoutbox at any time. 
$DBHost = 'localhost'; # your database host, usually localhost 
$DBUser = 'user_user'; # youer database user, set in cpanel 
$DBPass = 'password'; # your database password, set in cpanel 
$DBName = 'user_database'; # your database name, set in cpanel :o 


# Connects to the database 


mysql_connect("$DBHost", "$DBUser", "$DBPass")or die(mysql_error()); 
mysql_select_db("$DBName")or die(mysql_error()); 


switch ($_GET['act']){ # start the switch statement, we'll be testing for the variable $_GET['act'] 
default: # this is if none of the case's match, so it'll be the actual shoutbox and form to post a shout. 

$query=mysql_query("SELECT * FROM `shoutbox` ORDER BY id DESC LIMIT $limit"); 
# this is the query, it uses the $limit variable to limit how many shouts are to be shown. 
# Its also in DESC (descending) order newest to oldest. 

while ($row=mysql_fetch_array($query)){ # start the while loop to get all the shouts up to the limit in a list. 
$name=stripslashes($row['name']); # get the submitted name. 
$email=stripslashes($row['email']);
$website=stripslashes($row['website']); # get the submitted website. 
$message=stripslashes($row['message']); # get the message. 
$ip=stripslashes($row['ip']); # get the submitted ip address, we wont show this though. 
$id=$row['id']; 

if (!empty($email)){ # this checks to see if the email ISNT empty or NULL 
$name="<a href='mailto:$email'>$name</a>"; # if its not null, make the name a link to the email 
} 
if (!empty($website)){ # this checks to see if the email ISNT empty or NULL 
$name="<a href='$website'>$name</a>"; # if its not null, make the name a link to the email 
} 

##This is where you Change the Variables to say what the posted info says. 3$name is the users inputed name $message is message and so on its self explanatory.

echo "$name: $message "; # echo our $name and $message variable 


#This allows the user to delete his or her post. This only allows deletion from the same IP

if ($ip == $_SERVER["REMOTE_ADDR"]) { # only if the ip matches the current browsing ip 
echo "<br><a href='?act=del&id=$id'>Delete?</a>"; # shot the link 
} #close the if 

echo "<hr>"; # echo a horizontal rule to divide the shouts up 

} 

#this is the form area if you know html you may edit it

echo ' 
<form action="?act=shout" method="post" name="shout"> 
Name: <input name="name" type="text" size="20" maxlength="20"><br> 
Email: <input name="email" type="text" size="20" maxlength="30"> *<br> 
Website: <input name="website" type="text" size="20" maxlength="30"> *<br> 
Message:<br> 
<textarea name="message" cols="20" rows="3"></textarea><br> 
<input type="submit" name="Submit" value="Shout !"><br><br> 
* Denotes feild not required 
</form>'; 


break; # break out of the default 

case "shout"; # check to see if $_GET['act'] is equal to "shout" 

# 
## Now we'll get the data submitted from the form, since the form type was "post" 
## we'll be using the $_POST global function to recieve the data. 
## We must also clean the data. I used: 
## addslashes() - this adds backslashes to any of 'these' or "these" 
## htmlspecialchars() - this makes html useless by making things like < into &lt; ect. 
# 

$name=addslashes(htmlspecialchars($_POST['name'])); 
$email=addslashes(htmlspecialchars($_POST['email'])); 
$wesbite=addslashes(htmlspecialchars($_POST['wesbite'])); 
$message=addslashes(htmlspecialchars($_POST['message'])); 

# 
## Now we'll make sure that the required fields have been filled. 
## if they haven't we'll redirect the user to the form 
# 

if ($name == ""){ 
header("location: ?"); # '?' is just saying go to the default page 
} 
elseif ($message == ""){ 
header("location: ?"); 
} 
else { # else, if all the feilds have been filled - run the queries! 
$ip=$_SERVER["REMOTE_ADDR"]; # this is the global function for the ip, its for later use :) 
$sql=mysql_query("INSERT INTO `shoutbox` ( `id` , `name` , `email` ,  `website` , `message` , `ip` ) VALUES ('', '$name', '$email', '$website', '$message', '$ip')"); 



if (!$sql){ # if the query didnt run, tell the user 
echo "Error in mysql_query"; 
exit; # exit; closes the page, so no other queries or print is sent to the screen. 
} 

##Links back to the shoutbox script

echo "Post added successfully<br>"; 
echo "<a href='Your URL HERE'>Shoutbox?</a>"; 


} 
break; 
case "del"; 
 
if (is_numeric($_GET['id'])){ 

$ip=$_SERVER["REMOTE_ADDR"]; 
$id=$_GET['id']; # the id is already valid so no cleaning is nessasary 



$test=mysql_num_rows(mysql_query("SELECT * FROM `shoutbox` WHERE id ='$id' AND ip ='$ip' LIMIT 1")); 

 

if ($test == 1){ 

$sql=mysql_query("DELETE FROM `shoutbox` WHERE id =$id LIMIT 1"); 



if (!$sql){ # if the query didnt run, tell the user 
echo "Error in mysql_query"; 
exit; # exit; closes the page, so no other queries or print is sent to the screen. 
} 

# Tell the user success and give them a link to the shoutbox. 
echo "Success, your shout has been deleted.<br>"; 
echo "<a href='?'>Shoutbox?</a>"; 

} 

else { 
echo "You crafty demon, you didn't make that shout did you?<br>"; # give an error message and dont delete anything. 
echo "<a href='?'>Shoutbox?</a>"; #link back to the shoutbox 
} 

} 

else { 
echo "Invalid Id!"; # error message, and no delete 
} 

} 

?>
By the way this script only allows the user to post an email or a website address so be sure to go in and edit that yourself in the html .

Tommorrow if im not lazy perhaps ill add in a smiley mod.
oxymoron is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 04-23-2006, 05:32 PM
Junior Talker

Posts: 0
Hmmm you should create an admin interface but like you said this is rather simple
rebelagent is offline
Reply With Quote
View Public Profile
 
Old 04-26-2006, 11:29 PM
Junior Talker

Posts: 112
Thanks. But I found an easier to modify script somewhere elsee.. IT included pretty much everything. I just need to find the link again.. hmm
imported_ewwharhar is offline
Reply With Quote
View Public Profile
 
Old 04-27-2006, 10:08 PM
wirlwind1's Avatar
Junior Talker

Posts: 2
Usually people goto hotscript.com to find their scripts. Some site also sell databases too.
wirlwind1 is offline
Reply With Quote
View Public Profile
 
Old 04-28-2006, 07:25 PM
Junior Talker

Posts: 23
Admin Interface wouldnt me that hard really. Just look up a user interface tutorial and implement into the shoutbox
oxymoron is offline
Reply With Quote
View Public Profile
 
Old 05-12-2006, 03:24 PM
Junior Talker

Posts: 20
If you are really lazy, you can also just google "Free Shoutbox" or something similar to that, and they can give you a shoutbox with an admin interface. But I do prefer coding it myself.
Jasix is offline
Reply With Quote
View Public Profile
 
Old 05-17-2006, 07:15 PM
Junior Talker

Posts: 23
Yeah google is a great thing! it's how I learned PHP myself :-) Once you learn PHP shoutboxes are actually probably one of the simpler tasks along with blogs and news scripts.

it's the addons that get to you
oxymoron is offline
Reply With Quote
View Public Profile
 
Old 06-18-2006, 10:00 AM
Evo
Junior Talker

Posts: 157
i use hotscripts.com to find my shoutboxs they seem to be good.
Evo is offline
Reply With Quote
View Public Profile
 
Old 08-10-2006, 03:55 PM Re: shoutbox
Novice Talker

Posts: 7
Name: Joe Right
Hotscripts is the coolest. I found a very good shoutbox on there.
__________________
Untie The Knot Divorce Services.
Joe Right is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Create a simple Shout box
 

Thread Tools

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Webmaster Resources Marketplace:
Software Development Company | Webhosting.UK.com | Text Link Brokers 


   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.13755 seconds with 12 queries