Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
Ad icon
🎮 INDIAN PSN GIFT CARDS AVAILABLE NOW! 🎮
madukaperera
Updated:
Yesterday at 12:57 PM
🚀 Google AI PRO – 18 Months | Rs. 850 Only
lkkolla
Updated:
Monday at 4:56 PM
🔒 NordVPN Premium – 3 Months
hrdilshan
Updated:
Thursday at 8:29 PM
🚀 Microsoft Office 365 Pro Plus – Lifetime Access! 🚀
hrdilshan
Updated:
Thursday at 8:28 PM
Linkedin Premium Business / Careere /Sales Navigator - 1/2/3/6/9/12 Months - Reddem Link
hrdilshan
Updated:
Thursday at 8:27 PM
Electronics
Vehicles
Property
Search
Reply to thread
Forums
Computers & Internet
Software Development
Shoutbox
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="gazaly" data-source="post: 629066" data-attributes="member: 10197"><p>Making your own shoutbox at first might seem hard, but its simple and easy to make. Making a shoutbox can all be done with one file, specifically three steps, and you have to work backwards to have it function. First, you must make the submit action, which uploads the name and comments to the mySQL database. Secondly, you must have the display action which displays the comments. Finally, you need the form where the people can add the comments.</p><p>Before anything else though, you must make the mySQL database. I decided to add 4 fields to the database: id, name, message, and time. I called the table 'shoutbox' and the database 'news'. You can copy paste this code inside your mySQL database using a program such as PHPMyAdmin, or (type it in by hand if you feel so Here is the mySQL code I used:</p><p></p><p>CREATE TABLE `shoutbox` (</p><p>`id` int(11) NOT NULL auto_increment,</p><p>`name` text NOT NULL,</p><p>`message` longtext NOT NULL,</p><p>`time` text NOT NULL,</p><p>PRIMARY KEY (`id`)</p><p>) TYPE=MyISAM;</p><p></p><p>The rest of the code from now down can all be placed on one single</p><p>page. Here's what we need to do for the first step, for the submit</p><p>action.</p><p></p><p>1. First off, connect to the database.</p><p>2. If submit is hit, then get the day and time to be stored on the database.</p><p>3. Insert the values of the id, name, comments, and time to the database.</p><p></p><p>Here it is in PHP:</p><p></p><p>//the host, name, and password for your mysql</p><p>mysql_connect("localhost","username","password");</p><p></p><p>//select the database</p><p>mysql_select_db("news");</p><p></p><p>if($submit)</p><p>{</p><p>//use the PHP date function for the time</p><p>$time=date("h:ia d/j/y");</p><p></p><p>// inserting it into the shoutbox table which we made in the mysql statements before</p><p>$result=MYSQL_QUERY("INSERT INTO shoutbox (id,name,message,time)".</p><p>"VALUES ('NULL','$name', '$message','$time')");</p><p>}</p><p>?></p><p></p><p>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:</p><p></p><p>1. Select the last five messages posted from the shourbox table.</p><p>2. Run the while loop while it keeps getting an row.</p><p>3. Define each variable from the database and echo it out.</p><p></p><p>Here it is in PHP:</p><p></p><p>//returning the last 5 messages</p><p>$result = mysql_query("select * from shoutbox order by id desc limit 5");</p><p></p><p>//the while loop</p><p>while($r=mysql_fetch_array($result))</p><p>{</p><p>//getting each variable from the table</p><p>$time=$r["time"];</p><p>$id=$r["id"];</p><p>$message=$r["message"];</p><p>$name=$r["name"];</p><p>?></p><p></p><p></p><p>Finally, you have to write the form action for the shoutbox to load for</p><p>folks to post. Its not too hard, and sort of self explanatory:</p><p></p><p>Alright thats about it. You can see my code that I worked on: <a href="http://www.spoono.com/php/tutorials/shoutbox/shoutbox.txt" target="_blank">http://www.spoono.com/php/tutorials/shoutbox/shoutbox.txt</a></p><p>In fact, the one for this tutorial is only 35 lines total. Make a new file and save it as shoutbox.php and put all of the code on this tutorial in the body.</p></blockquote><p></p>
[QUOTE="gazaly, post: 629066, member: 10197"] Making your own shoutbox at first might seem hard, but its simple and easy to make. Making a shoutbox can all be done with one file, specifically three steps, and you have to work backwards to have it function. First, you must make the submit action, which uploads the name and comments to the mySQL database. Secondly, you must have the display action which displays the comments. Finally, you need the form where the people can add the comments. Before anything else though, you must make the mySQL database. I decided to add 4 fields to the database: id, name, message, and time. I called the table 'shoutbox' and the database 'news'. You can copy paste this code inside your mySQL database using a program such as PHPMyAdmin, or (type it in by hand if you feel so Here is the mySQL code I used: 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. 1. First off, connect to the database. 2. If submit is hit, then get the day and time to be stored on the database. 3. Insert the values of the id, name, comments, and time to the database. Here it is in PHP: //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: 1. Select the last five messages posted from the shourbox table. 2. Run the while loop while it keeps getting an row. 3. Define each variable from the database and echo it out. Here it is in PHP: //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"]; ?> 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: Alright thats about it. You can see my code that I worked on: [url]http://www.spoono.com/php/tutorials/shoutbox/shoutbox.txt[/url] In fact, the one for this tutorial is only 35 lines total. Make a new file and save it as shoutbox.php and put all of the code on this tutorial in the body. [/QUOTE]
Insert quotes…
Verification
Payakata winadi keeyak tibeda?
Post reply
Top
Bottom