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.