
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.
<?
//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:
<?
//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>Alright thats about it. You can see my code that I worked on and made sure worked by right clicking and saving shoutbox.txt. I hope this helps and if you have any questions or comments, feel free to e-mail and we'll help you out :)
Copyright © 2000-2008 Spoono, LLC. All rights reserved.
Network: Reseller Web Hosting by Spoono Host | Spoonloads | Absolute Cross
Terms of Service | Privacy Policy.