コード例 #1
0
//定义个常量,用来授权调用includes里面的文件
session_start();
define('IN_TG', true);
//引入公共文件
//定义一个常量,用来指定本页的内容
define('SCRIPT', 'register');
require dirname(__FILE__) . '/includes/common.inc.php';
//引入验证文件
include ROOT_PATH . 'includes/check.func.php';
//判断是否登录
if (!isset($_COOKIE['username'])) {
    _location("请先登录", 'login.php');
} else {
    //创建一个空数组,用来存放提交过来的合法数据
    $_clean = array();
    $_clean['order_id'] = _build_order_no();
    $_clean['username'] = $_COOKIE['username'];
    $_clean['food_id'] = $_POST['food_id'];
    $_clean['re_name'] = $_POST['re_name'];
    $_clean['phone'] = $_POST['phone'];
    $_clean['address'] = $_POST['address'];
    $_clean['remarks'] = $_POST['remarks'];
    $_clean['quantity'] = $_POST['quantity'];
    $_row = _fetch_array("SELECT stock FROM tb_food WHERE id='{$_clean['food_id']}'");
    if ($_row['stock'] >= $_clean['quantity']) {
        //将表单数据保存到数据库
        _query("INSERT INTO tb_orders (\n\t\t\t\t\t\t\t\t\t\torder_id,\n\t\t\t\t\t\t\t\t\t\tusername,\n\t\t\t\t\t\t\t\t\t\tre_name,\n\t\t\t\t\t\t\t\t\t\tphone,\n\t\t\t\t\t\t\t\t\t\taddress,\n\t\t\t\t\t\t\t\t\t\tremarks,\n\t\t\t\t\t\t\t\t\t\torder_time\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tVALUES(\n\t\t\t\t\t\t\t\t\t\t'{$_clean['order_id']}',\n\t\t\t\t\t\t\t\t\t\t'{$_clean['username']}',\n\t\t\t\t\t\t\t\t\t\t'{$_clean['re_name']}',\n\t\t\t\t\t\t\t\t\t\t'{$_clean['phone']}',\n\t\t\t\t\t\t\t\t\t\t'{$_clean['address']}',\n\t\t\t\t\t\t\t\t\t\t'{$_clean['remarks']}',\n\t\t\t\t\t\t\t\t\t\tNOW()\n\t\t\t\t\t\t\t\t\t)");
        if (_affected_rows() == 1) {
            _query("INSERT INTO tb_order_items (\n\t\t\t\t\t\t\t\t\t\t\t\torder_id,\n\t\t\t\t\t\t\t\t\t\t\t\tfood_id,\n\t\t\t\t\t\t\t\t\t\t\t\tquantity\n\t\t\t\t\t\t\t\t\t\t\t)VALUES(\n\t\t\t\t\t\t\t\t\t\t\t\t'{$_clean['order_id']}',\n\t\t\t\t\t\t\t\t\t\t\t\t'{$_clean['food_id']}',\n\t\t\t\t\t\t\t\t\t\t\t\t'{$_clean['quantity']}'\n\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t");
            if (_affected_rows() == 1) {
                _query("DELETE FROM tb_shoppingcart WHERE username='******'username']}' AND food_id='{$_clean['food_id']}'");
コード例 #2
0
ファイル: test.php プロジェクト: zhangshuhui2014/foodcool
<?php

include 'includes/global.func.php';
echo _build_order_no();