Php+ajax to realize _php skills of news message system without refreshing

Source: Internet
Author: User

This article introduced a no refreshing news message system, the most concise and understandable an AJAX no refresh message system, the source code omitted the process of accepting data validation, we can expand according to their needs, the following into the theme.

Core Source:

1. Configuration file: config.php, the code is as follows:

<?php 
 //Database configuration information (username, password, database name, table prefix, etc.) 
 $cfg _dbhost = "localhost"; 
 $cfg _dbuser = "root"; 
 $cfg _dbpwd = "root"; 
 $cfg _dbname = "Ajaxdemo1"; 
 $cfg _dbprefix = ""; 
 $link = mysql_connect ($cfg _dbhost, $cfg _dbuser, $cfg _dbpwd); 
 mysql_select_db ($cfg _dbname); 
 mysql_query ("Set names UTF8"); 

2. Processing request: Deal.php, the code is as follows:

<?php 
 Header ("Content-type:text/html;charset=utf-8"); 
 Include "config.php"; 
 The POST receives the data, only demonstrates the effect, here eliminates the verification 
 $name = $_post[' name ']; 
 $content = $_post[' content ']; 
 $sql = "INSERT INTO Test (name,content) values (' {$name} ', ' {$content} ');"; 
 $res = mysql_query ($sql, $link); 
 if ($res) { 
 echo ' {' name ': '. $name. ', ' content ': '. $content. ', ' status ': ' 1 '} '; 
> 

3. Home code: index.php, code as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">  

Database file with the following code:

DROP TABLE IF EXISTS ' test '; 
CREATE TABLE ' test ' ( 
 ' id ' int (a) unsigned NOT null auto_increment, 
 ' name ' varchar ' (+) not NULL, 
 ' content ' te XT not NULL, 
 PRIMARY KEY (' id ') 
) Engine=myisam DEFAULT Charset=utf8; 

The above is for you to share the php+ajax to achieve no refreshing news message system, I hope to help you learn.

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.