Jump to content
xisto Community
Sign in to follow this  
.hack//GU

Simple Shoutbox In Php

Recommended Posts

This is a simple shoutbox I created in the past for my class.

shout!box.php

<html> <head>  <title>  Projekt Shout!box  </title> </head> <body>  <form action="shout!box_prc.php" method="post">   <table border="2" align="center" width="400">	<tr>	 <td align="center">SHOUT!!!BOX</td>	</tr>	<tr height="300">	 <td align="center" width="300" > 	  <table border="1">	   <?php		$connection=mysql_connect("localhost","root","");	if($connection)	{	 $db="shoutbox";		 $query="select * from data order by id desc";		 $db_query=mysql_db_query($db,$query);		 $fetch=mysql_fetch_array($db_query);$count=0;		 do		 {				  echo $fetch['id']."-".$fetch['sender'].": ".$fetch['message']."<br>";		  $count++;		 } while (($fetch=mysql_fetch_array($db_query)) && ($count<10));	}	else	{	 echo "Connection failed";	}	mysql_close($connection)		?>	  </table>	 </td>	</tr>	<tr>	 <td align="center">	  Sender:<input type="text" name="sender">	 </td>	</tr>	<tr>	 <td align="center">	  Message:<input type="memo" name="message">	 </td>	</tr>	<tr>	 <td align="center"><input type="submit" value="Submit"></td>	</tr>   </table>  </form> </body></html>

shout!box_prc.php
<html><title>Processing...</title></html><?php $connection=mysql_connect("localhost","root",""); if($connection) {  $_POST[sender] =strip_tags($_POST[sender] ,"<b><i><u>");  $_POST[message]=strip_tags($_POST[message],"<b><i><u>");  $db="shoutbox";  $query="insert into data(sender,message) values('$_POST[sender]','$_POST[message]')";  $insert=mysql_db_query($db,$query);  if ($insert) echo "Success";  else echo "Failed to insert";  echo "<a href='shout!box.php'>Return</a>"; } mysql_close($connection); ?>

shout!box_adm.php
<title>Admin Page</title><?php $connection=mysql_connect("localhost","root",""); if($connection) {   $db="shoutbox";   $query="select * from data order by id asc";   $db_query=mysql_db_query($db,$query);   $fetch=mysql_fetch_array($db_query);   do   {			 echo $fetch['id']."-".$fetch['sender'].": ".$fetch['message'];	 echo "<a href=shout!box_edt.php?code=$fetch[id]> Edit</a>"." "."<a href=shout!box_del.php?code=$fetch[id]>Delete</a>"."<br>";	     } while ($fetch=mysql_fetch_array($db_query)); } mysql_close($connection);?>

shout!box_del.php
<title>Deletion</title><?php $connection=mysql_connect("localhost","root",""); if($connection) {   $db="shoutbox";   $query="delete from data where id=$_GET[code]";   $db_query=mysql_db_query($db,$query);   if($db_query) echo "Deleted succesfully";	else 	 echo "Failed";   echo "<a href=shout!box_adm.php>Return</a>"; } mysql_close($connection);?>

shout!box_edt.php
<title>Deletion</title><?php $connection=mysql_connect("localhost","root",""); if($connection) {   $db="shoutbox";   $query="select * from data where id=$_GET[code]";   $db_query=mysql_db_query($db,$query);   $fetch=mysql_fetch_array($db_query);   echo "<form action=shout!box_edt2.php?code=$_GET[code] method=post>";   echo "<b>Update</b>:<br>		 Old:".$fetch[sender]."<br>	 New: <input type=text name=sender2><br><br>	 Old:".$fetch[message]."<br>	 New: <input type=text name=message2><br><br>	 <input type=submit value=Update>";   echo "</form>"; } mysql_close($connection);?>

shout!box_edt2.php
<title>Edit</title><?php $connection=mysql_connect("localhost","root",""); if($connection) {   $_POST[sender2] =strip_tags($_POST[sender2] ,"<b><i><u>");   $_POST[message2]=strip_tags($_POST[message2],"<b><i><u>");   echo $_POST[sender2];   $db="shoutbox";   $query="update data set sender='$_POST[sender2]', message='$_POST[message2]' where id=$_GET[code]";   $db_query=mysql_db_query($db,$query);   if($db_query) echo "Update Succesful";	else 	 echo "Failed";   echo "<a href=shout!box_adm.php>Return</a>"; } mysql_close($connection);?>

SQL Query

CREATE DATABASE `shoutbox`;USE shoutbox;CREATE TABLE `data` (  `id` int(10) NOT NULL auto_increment,  `sender` varchar(30) NOT NULL default '',  `message` text NOT NULL,  PRIMARY KEY  (`id`)) TYPE=MyISAM COMMENT='Data for shoutbox' AUTO_INCREMENT=13;INSERT INTO `data` VALUES (1, 'DivL', 'Hello');INSERT INTO `data` VALUES (2, 'DivL', 'Alo');INSERT INTO `data` VALUES (3, 'Alo', ' juga');INSERT INTO `data` VALUES (4, 'fd', 'fd');INSERT INTO `data` VALUES (5, 'w', 's');INSERT INTO `data` VALUES (6, 'w', 'f');INSERT INTO `data` VALUES (7, 'e', 'f');INSERT INTO `data` VALUES (8, 'e', 'fd');INSERT INTO `data` VALUES (9, 'e', 'e');INSERT INTO `data` VALUES (10, 'g', 'g');

Share this post


Link to post
Share on other sites

It seems good, but do you think you could possibly give a brief expanation of what each segment of code does exactly? You know, for those of us who aren't so fluent in php but might want to make tiny modifications to such a shoutbox.

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.