示例#1
0
<?php

/**
	* Lession 2:Submit form by ajax
	* @github https://github.com/vihoangson/Program_lesson.git
	* @author Vi Hoàng Sơn <*****@*****.**>
**/
require_once "class/sqlite.php";
require_once "class/lesson2.php";
$sqlite = new My_sqlite();
$lesson2 = new Lesson2($sqlite);
if (preg_match("/^do_/", $_GET["do"])) {
    $lesson2->{$_GET["do"]}();
}
if (!empty($_POST["post"])) {
    $user_name = $_POST["name_txt"];
    $user_email = $_POST["email_txt"];
    $user_age = $_POST["age_txt"];
    $user_sex = $_POST["sex_txt"];
    $user_phone = $_POST["phone_txt"];
    $user_note = $_POST["note_txt"];
    $user_finger = $_POST["finger_txt"];
    $user_id = $_POST["id_txt"];
    if ($user_id) {
        $sql = 'UPDATE user SET
		user_name	= "' . $user_name . '",
		user_email	= "' . $user_email . '",
		user_age	= "' . $user_age . '",
		user_sex	= "' . $user_sex . '",
		user_phone	= "' . $user_phone . '",
		user_note	= "' . $user_note . '",
示例#2
0
<?php

/**
	* Lesson 5: AutoSave in Jquery
	* @author Vi Hoàng Sơn <*****@*****.**>
**/
require_once "class/sqlite.php";
require_once "class/lesson5.php";
$sqlite = new My_sqlite();
$lesson5 = new Lesson5($sqlite);
if ($_POST["ajax"]) {
    //
    // Security mod filter variable before save (true|false)
    //
    $security_mod = true;
    if ($security_mod) {
        $text = base64_encode($_POST["text"]);
    } else {
        $text = $_POST["text"];
    }
    $sql = "SELECT * FROM text_tb where text_id=1 ";
    $rs = $sqlite->query($sql);
    $data = $sqlite->fetchAll($rs);
    if (count($data) == 0) {
        $sql = 'INSERT INTO text_tb("text_id","text_c") VALUES (1,"' . $text . '");';
    } else {
        $sql = 'UPDATE text_tb SET	text_c	= "' . $text . '"	WHERE text_id=1';
    }
    if (!$sqlite->exec($sql)) {
        $error = true;
        echo 0;