Simple php + mysql chat room implementation (with source code) _ PHP

Source: Internet
Author: User
This article mainly introduces the implementation methods of php + mysql chat rooms, details the database, Framework page, login and information release and display function implementation skills, the complete source code is provided for readers to download and reference. if you need it, you can refer to the following example to describe a simple php + mysql chat room implementation method. We will share this with you for your reference. The details are as follows:

The program described here is divided into eight files:

Frameset framework page: index. php

Show. php

User logon page: login. php

User speech page: speak. php

Database configuration file: config. php

Page beautification style: style.css

Database File: chat. SQL

Statement form: face/

They are described as follows:

I. the database file chat. SQL is as follows:

SET FOREIGN_KEY_CHECKS = 0; -- ------------------------------ Table structure for 'chat' -- ---------------------------- drop table if exists 'chat'; create table 'chat' ('chtime' datetime default NULL, 'Nick 'char (10) not null, 'word' char (150) default NULL, 'face' int (11) default NULL) ENGINE = InnoDB default charset = gb2312; -- ------------------------------ Records of chat ----------------------------- -Insert into chat VALUES ('2017-03-21 04:15:14 ', 'smiling', 'Test display statement', '3 '); insert into chat VALUES ('2017-03-21 04:46:26 ', 'smiling', 'Time is incorrect,', '5 '); insert into chat VALUES ('2017-03-21 04:47:28 ', 'php newbie', 'newbie is coming. ', '1'); insert into chat VALUES ('2017-03-21 04:55:19', 'php newbie ', 'display correct', '6 '); insert into chat VALUES ('2017-03-21 17:12:47 ', 'php newbie', 'correct display time', '5 '); insert into chat VALUES ('2017-03-21 17:23:19 ', 'php newbie', 'Time displayed correctly. ', '7'); insert into chat VALUES ('2017-03-21 17:23:29', 'php newbie ', 'Haha', '1 '); insert into chat VALUES ('2017-03-22 08:28:00 ', '', 'Come back today. ', '3 ');

II. the Framework page is as follows:

 Simple php + mysql chat room-framework page       
 
  
<Body> </body>
 

3. the login. php page is as follows:

Simple php + mysql chat room-login page
 
 
 
<? Php if ($ _ GET ["tj"] = "out") {setcookie ("nick", "", time ()-3600); header ("refresh: 0; URL = 'login. php '");} if ($ _ POST [" submit "]) {setcookie (" nick ", $ nick); // use cookies to record user nicknames, you can also use SESSION header ("refresh: 0; URL = 'login. php '") ;}?> <? Php if ($ _ COOKIE ["nick"]) {echo "welcome ". $ _ COOKIE ["nick"]. "Exit Room";} else {echo "enter your nickname" ;}?>
Program Description: This chat room is a program written by the author only for one day, so it is only suitable for beginners to practice and study, and experts can bypass it, new users can add the IP address and other field functions on the basis of this, the most important is to understand the production principles of this program. New friends are welcome to join the summer source code exchange group:101140934

4. the speak. php page is as follows:

Simple php + mysql chat room-Speech page
 
 
 

5. show. php:

<? Php require_once ('config. php');?> <? Phpif ($ words) {$ query = "insert into chat (chtime, nick, words, face) values (now (), '$ nick', '$ words ', '$ face') "; // Insert SQL statement mysql_query ($ query, $ link_ID); // send a message to the database header (" refresh: 0; URL = 'Show. php '") ;}?>Simple php + mysql chat room-display the message page
 
 <? Php // The latest statement is shown at the bottom $ SQL = "select * from chat order by chtime asc"; $ result = mysql_query ($ SQL ); $ total = mysql_num_rows ($ result); $ info = ($ total/15-1) * 15; if ($ total <15) {$ str = "select * from chat order by chtime asc;"; // query string} else {$ str = "select * from chat order by chtime asc limit $ info, 15; "; // query string} $ result = mysql_query ($ str, $ link_ID); // send the query while ($ row = mysql_fetch_array ($ result) {?>
 
 
Nickname: <? Php if ($ row [nick] = "") {echo "" ;}else {echo $ row [nick] ;}?> . GIF "width =" 20 "height =" 20 "> Statement content: <? Php echo $ row [words];?> Time: <? Php echo $ row [chtime];?>
<? Php }?>

Click here to download the complete instance code.

I hope this article will help you with PHP programming.

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.