Creating Shout Box in PHP


In this article I explain how to create a shoutbox in PHP. Creating a shoutbox using a MySQL database to store shouts in a table. First of all I will create a simple HTML file and then creating a database. In the database a table is created and the table name is "shoutbox".


This is a HTML file to be saved as form.html:



<title>My Shout Box Form</title>


<body bgcolor="#FCFBDC">

<form action="shoutbox.php" method="post" >


<input type="text" name="name" size=30 maxlength='100'></input><br/>


<input type="text" name="message" size=30 maxlength='100'></input><br/>

<input type="submit" name="submit" value="submit"></input>




This is a PHP file; save this file as "shoutbox.php". In this file is a builtin connection file. I have created a database with MySQL to save the shoutbox in our table. In this database you will need to create four fields for Id, name, message and time.

This is the table for storing the shouts:

Shoutbox save in database.jpg 






$time= date("F j, Y, g:i a");

$result=MYSQL_QUERY("INSERT INTO shoutbox (id,name,message,time)".

"VALUES ('NULL','$name', '$message','$time')");

$result = mysql_query("select * from shoutbox order by id desc limit 5");







echo $name."<br/>".$message."<br/>".$time."<br/>";



Shoutbox in php.jpg

Here, you will enter the name and message then press the submit button so your shouts data is saved in your table.

Shoutbox in php1.jpg

Here, show your shouts data fetched from the table.

Shoutbox in php2.jpg

Up Next
    Ebook Download
    View all
    View all