Help - Search - Members - Calendar
Full Version: Simple shoutbox
Pixel2Life Forum > Member Tutorials and Requests > Forum Tutorial Archives > PHP Tutorials
fedekiller
In this tutorial i will explain how to make a simple shoutbox
For this tutorial, you will need an sql host, if you dont have one, you can get it in http://freesql.org

1. Create a new table, for that, run this code
CODE
CREATE TABLE `shoutbox` (
`id` int(11) NOT NULL auto_increment,
`name` text NOT NULL,
`message` longtext NOT NULL,
PRIMARY KEY  (`id`)
) TYPE=MyISAM;


2. Now make a new document and paste this code
CODE
<style type="text/css">
<!--
body,td,th {
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 10px;
    color: #000000;
}
-->
</style><table width="200" height="200" border="0">

 <tr>
   <td><iframe scrolling="auto" src="show.php">
    </iframe>
    </td>
 </tr>
</table>
<form action="shoutbox2.php" method="post">
 <p>Name<br>  
   <input name="name_txt" type="text" id="name_txt">
</p>
 <p>Message<br>
   <textarea name="message_txt" id="message_txt"></textarea>
 </p>
</p>
 <p>
   <input type="submit" name="Submit" value="blah">  
 </p>
</form>

Save it as shout.php
In that code, im bassically making the "form" and the "style"

2. Make nother document, and paste this code
CODE
<style type="text/css">
<!--
body,td,th {
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 10px;
    color: #000000;
}
-->
</style><?
$name= $_POST["name_txt"];
$message= $_POST["message_txt"];
mysql_connect("localhost","your_username","your_pass");
mysql_select_db("your_database");
MYSQL_QUERY("INSERT INTO shoutbox (id,name,message)".
     "VALUES ('NULL','$name', '$message')");
?>
<?
echo "Shout posted, <a href=shout.php>go back</a>"
?>

Now save it as shoutbox2.php . Here i aply style too but im sending the form too

3. Make another document and paste this code
CODE
<style type="text/css">
<!--
body,td,th {
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 10px;
    color: #000000;
}
-->
</style><?
mysql_connect("freesql.org","spoono_db","pokemon") or die(mysql_error());
   mysql_select_db("spoono_db") or die(mysql_error());
   $query = "SELECT message, name
FROM shoutbox order by id DESC LIMIT 10";
   $result = mysql_query($query);
   echo "<TABLE>";
   while($r=mysql_fetch_array($result))    
   {
       echo "<TR>
           <TD><font-size: 10px;>
<strong>$r[name]</A></font></TD></strong>
       </TR>
       <TR>
           <TD><font-size: 10px;>$r[message]</font></TD>
       </TR>
       <TR>
           <TD><HR></TD>
       </TR>";
       
   }
   echo "</TABLE>";
?>

Here i apply style too tongue.gif but im bassicaly showing the information of the database
save this as show.php.

4. Now upload all the files to your server and enjoy your shoutbox happy.gif
/quit
Wow, nice tut, I was gonna search that on hotscripts, but now i dont have to!
Donna
QUOTE(anti_angel @ Jun 29 2005, 08:06 PM)
Wow, nice tut, I was gonna search that on hotscripts, but now i dont have to!

ph34r.gif http://www.pixel2life.com/tutorials/All/Al...d=1&ss=shoutbox
fedekiller
but my code is much more easure happy.gif
Klubba
I don't like that you use iframes, i would had used the PHP-command; include. But nice tutorial anyways, keep up the good work shades.gif
fedekiller
you can also make a new page and put

<?
include ("show.php")
?>
fiv3isaliv3
why not just have it post to itself rather then using more then one page?
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.