Using Php+mysql to build a chat room function instance Code _php tutorial

Source: Internet
Author: User
Below, take a simple chat room design as an example, introduce the application of Php+mysql in Web development

1. Overall design

1.1 Conception and Planning:
The basic principle of the chat room is to store the spoken data transmitted by each user connected to the same page, and then pass all the statements to each user. That is, the database is used to assemble each person's speech, and the data in the database to everyone to realize the function of the chat room.
1.2 Table Design
First use MySQL to create table chat to store users ' speeches:
Copy CodeThe code is as follows:
mysql> CREATE TABLE Chat
(Chtime Datatime,
Nick CHAR (+) is not NULL,
->words CHAR (150));

Only three fields are set in the table, Chtime is the time to speak, Nick is the speaker's nickname, words is the content of the statement, the speech is up to 150 characters
1.3 Web Design
One of the simplest chat rooms usually requires two page boxes: a page box is a form that the user enters to speak, and the other is used to show the speakers. So the code snippet usually requires at least the following segments:
Build the structure of the page frame (main.php)
Procedural section showing members ' statements (cdisplay.php)
Program segment for transmitting user statements (speak.php)
User login into the chat room program segment (login.php)

  2. Code Design

When the above planning is complete, you can start code design, using PHP can be very concise implementation of the above functions.
2.1 User Login login.php, this section of code is a full HTML page
Copy CodeThe code is as follows:


  <title>User Login</title>

Please enter your nickname





After completing the above work, a simple chat room production is completed. Of course, the designer can do some personalized design according to personal interests, such as adding a page box, display the current chat room staff list, add expression, get speaker IP, further beautify the page and so on.

http://www.bkjia.com/PHPjc/325728.html www.bkjia.com true http://www.bkjia.com/PHPjc/325728.html techarticle below, take a simple chat room design as an example, introduce the application of Php+mysql in Web Development 1, the overall design 1.1 conception and planning: the basic principle of chat room, is to connect each with ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.