PHP Web version chat software implementation code _php instance

Source: Internet
Author: User

This example for you to share the PHP anonymous chat room of the specific implementation code for your reference, the specific contents are as follows

1. index.html

 

2. action.php

<?php
 
$link = mysqli_connect (' localhost ', ' root ', ' 123 ', ' Test ');
Mysqli_query ($link, ' Set names UTF8 ');
$info = Array ();
Header ("content-type:text/html; Charset=utf-8 ");
$id =$_get[' Maxid '];
$data = Mysqli_query ($link, "select * from Talk where id> $id");
while ($array = Mysqli_fetch_assoc ($data)) {
 $info [] = $array;
};
 
 echo Json_encode ($info);

3. Chat.sql

DROP TABLE IF EXISTS ' talk ';
CREATE TABLE ' Talk ' (
 ' id ' int "unsigned not NULL auto_increment COMMENT ' id ',
 ' send ' varchar () CHARACTER S ET UTF8 default null COMMENT ' sender nickname ',
 ' IP ' varchar (a) CHARACTER SET UTF8 DEFAULT null,
 ' content ' varchar (C) Haracter SET UTF8 default null,
 ' time ' varchar default NULL,
 PRIMARY KEY (' id ')
engine=innodb auto_i ncrement=52 DEFAULT Charset=utf8;

4. add.php

<?php
 
/**
 * @ feature inserts the form into the database * * * *
$content =$_post[' content '];
Print_r ($_post);
$time = Date ("Y-m-d h:i:s", Time (0));
$link = Mysqli_connect (' localhost ', ' root ', ' 123 ', ' Test ');
Mysqli_query ($link, ' Set names UTF8 ');
$ip = $_server["REMOTE_ADDR"];
$sql = "INSERT into Talk VALUES (NULL, ' Anonymous ', ' $ip ', ' $content ', ' $time ')";
$data = Mysqli_query ($link, $sql);
echo "$content";
if ($data)
 echo "1";
 else
  echo "0";

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.