jQuery Ajax 插入数据库示例

wp_jquery_ajax_insert.php

PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


    jQery Ajax Insert Example
    
    
    
    


wp_jquery_ajax_insert_process.php

php
    require_once 'db.php';
    
    $post_text = mysql_real_escape_string($_POST['data'],$conn);
    
    if(!mysql_query("INSERT INTO `wp_jquery_ajax_insert`(text) VALUES('$post_text')",$conn)){
        echo 'Failed!'.mysql_error($conn);
    }else {
        echo 'Success!';
    }

//End_php

表 wp_jquery_ajax_insert SQL

CREATE TABLE `wp_jquery_ajax_insert` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `text` varchar(1024) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8

 

db.php

View Code
php
static $connect = null;
static $table = '';
if(!isset($connect)) {
    $connect = mysql_connect("localhost","root","");
    if(!$connect) {
        $connect = mysql_connect("localhost","Zjmainstay","");
    }
    if(!$connect) {
        die('Can not connect to database.Fatal error handle by /test/db.php');
    }
    mysql_select_db("test",$connect);
    mysql_query("SET NAMES utf8",$connect);
    $conn = &$connect;
    $db = &$connect;
}

 

 

 

转载于:https://www.cnblogs.com/Zjmainstay/archive/2012/06/04/jQery_Ajax_Insert.html

你可能感兴趣的:(jQuery Ajax 插入数据库示例)