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 information of HTML and PHP are required. Ok, lets begin now.
Step 1: Design Database Table. Create table "chat" in MySQL database to store basic chat data
: chtime (chat measure
), nick (user nickname) and words (chat communication
, 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, communication
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)
<html>
<head>
<title
>User Login</title>
</head>
<body>
Please input your nickname and enter
<form action="main.php" method="post" target="_self">
<input type="text" title
="nick" cols="20">
<input type="submit" assessment of value="login">
</form>
</body>
</html>
2. main.php
<?
setcookie("nick",$nick) //utilize cookie to store user nickname
?>
<html>
<name
>My Chat Room</title
>
<frameset rows="80