Home | Articles|Namespace|Interview Questions|Tools|Jobs|Projects|Community
Asp.net Tutorials

»Dotnet Ads
»Message Boards
Message Boards
Dotnet Books

»Member Details
Register
Login
LogOut
Submit Code
Submit Jobs
Submit Projects

»Competition
Community
Winners
Prizes
Write For Us
Members

»Other Resources
Links
Dotnet Resources

Design an Online Chat Room with PHP and MySQL

In this article, you will learn how to design and develop a simple online chat room with PHP and MySQL. This tutorial explains every steps of the development, including both database design and PHP programming. Basic computer skills and knowledge of HTML and PHP are required. Ok, let's begin now.


Step 1: Design Database Table. Create table "chat" in MySQL database to store basic chat information: chtime (chat time), nick (user nickname) and words (chat message, less than 150 characters)



mysql> CREATE TABLE chat


-> chtime DATATIME,


-> nick CHAR (10) NOT NULL,


-> words CHAR (150);



Step 2: Design Structure. This simple online chat room includes the following four sections: user login, message display, message input and a main frame integrating the display and input sections. Thus, it needs the following four files to work: login.php, main.php, display.php and speak.php.



Step 3: Write the code


1. login.php (just a HTML form)




User Login




Please input your nickname and enter











2. main.php



setcookie("nick",$nick) //use cookie to store user nickname


?>



My Chat Room







3. display.php


This file is used to get message records from database and display the results. To keep the size of database, old messages are deleted and only the newest 15 messages are displayed.




Display Messages






//connect to mysql server, server name: main, database username:

Have a Question and dont know the answer post it below and get answers in minutes

Due to spam this feature is disabled
To get answers fast , make sure you enter a detailed subject for example: "DataGrid issues need answer" not "DataGrid"

Subject:

Catjegory Name:

Message:



© 2008 dotnetwatch.com -- Privacy policy