thinkphp3.2 留言板内容提交到数据库
2015-11-23 00:21
597 查看
1.配置
<?php
return array(
//'配置项'=>'配置值'
'DEFAULT_MODULE' => 'Admin', // 默认模块
'DEFAULT_CONTROLLER' => 'Index', // 默认控制器名称
'DEFAULT_ACTION' => 'index', // 默认操作名称
'DB_TYPE' => 'mysqli', // 数据库类型
'DB_HOST' => 'localhost', // 服务器地址
'DB_NAME' => 'thinkphp0421', // 数据库名
'DB_USER' => 'root', // 用户名
'DB_PWD' => 'root', // 密码
'DB_PORT' => '3306', // 端口
'DB_FIELDS_CACHE' => true, // 启用字段缓存
'URL_MODEL' => 0,// 0 普通模式, 1, pathinfo模式 ,2. rewirte模式 3. 兼容模式
'SHOW_PAGE_TRACE' => true, //打开Trace Page 调试页
// 'TMPL_ENGINE_TYPE' =>'smarty'
);
----------**-----------------------**------- <br>
2. 前端代码 /tp-ceshi/Application/Admin/View/Goods/edit.html
<!-- $Id: brand_info.htm 14216 2008-03-10 02:27:21Z testyang $ -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>ECSHOP 管理中心 - {$meta_title} </title>
<meta name="robots" content="noindex, nofollow">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="__CSS__/general.css" rel="stylesheet" type="text/css" />
<link href="__CSS__/main.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>
<span class="action-span"><a href="brandList.html">商品商品</a></span>
<span class="action-span1"><a href="#">ECSHOP 管理中心</a></span>
<span id="search_id" class="action-span1"> - {$meta_title} </span>
<div style="clear:both"></div>
</h1>
<div class="main-div">
<form method="post" action="{:U()}" enctype="multipart/form-data" >
<table cellspacing="1" cellpadding="3" width="100%">
<tr>
<td class="label">商品名称</td>
<td>
<input type="text" name="goods_name" maxlength="60" value="{$goods->goods_name}" />
<span class="require-field">*</span>
</td>
</tr>
<tr>
<td class="label">商品价格</td>
<td>
<input type="text" name="goods_price" value="{$goods:goods_price}" />
</td>
</tr>
<tr>
<td class="label">商品数量</td>
<td>
<input type="text" name="goods_number" value="{$goods_number}" />
</td>
</tr>
<tr>
<td class="label">商品描述</td>
<td>
<textarea name="goods_introduce" cols="60" rows="4" ></textarea>
</td>
</tr>
<tr>
<td colspan="2" align="center"><br />
<input type="submit" class="button" value=" 确定 " />
<input type="reset" class="button" value=" 重置 " />
</td>
</tr>
</table>
</form>
</div>
<div id="footer">
共执行 1 个查询,用时 0.018952 秒,Gzip 已禁用,内存占用 2.197 MB<br />
版权所有 © 2005-2012 上海商派网络科技有限公司,并保留所有权利。</div>
</body>
</html>
------------------------***-------------------------**----------------<br>
3.模型 /tp-ceshi/Application/Admin/Model/GoodsModel.class.php
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 14-6-23
* Time: 下午2:08
*/
namespace Admin\Model;
use Think\Model;
class GoodsModel extends Model{
}
---------------------**---------------------------------***----------------------<br>
4. 控制器 /tp-ceshi/Application/Admin/Controller/GoodsController.class.php
<?php
namespace Admin\Controller;
use Think\Controller;
class GoodsController extends Controller{
public function add(){
if(IS_POST){
$goodsModel = D('Goods');
$goodsModel->create();
if($goodsModel->add(I('post'))){
$this->success('保存成功',U('index'));
}else{
$this->error('保存失败!'.$goodsModel->getError());
}
}else{
$this->display('edit');
}
}
}
-----------------------**---------------------------------**---------------------<br>
5. 数据库 thinkphp0421 ---> goods.sql
数据库
/*
Navicat MySQL Data Transfer
Source Server : root
Source Server Version : 50540
Source Host : localhost:3306
Source Database : thinkphp0421
Target Server Type : MYSQL
Target Server Version : 50540
File Encoding : 65001
Date: 2015-11-22 05:06:33
*/
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for goods
-- ----------------------------
DROP TABLE IF EXISTS `goods`;
CREATE TABLE `goods` (
`goods_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增id',
`goods_name` varchar(128) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '商品名称',
`goods_price` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '价格',
`goods_number` int(11) NOT NULL DEFAULT '100' COMMENT '数量',
`goods_introduce` text COLLATE utf8_unicode_ci COMMENT '详细介绍',
`goods_big_img` varchar(128) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '商品图片',
`goods_small_img` varchar(128) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '商品小图',
`goods_create_time` int(11) NOT NULL DEFAULT '0' COMMENT '添加时间',
`goods_last_time` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`goods_id`)
) ENGINE=InnoDB AUTO_INCREMENT=56 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='商品表';
-- ----------------------------
-- Records of goods
-- ----------------------------
INSERT INTO `goods` VALUES ('1', '1', '0.00', '100', '1', '1', '1', '0', '0');
INSERT INTO `goods` VALUES ('2', '2', '0.00', '2', '1', '1', '1', '0', '0');
-------------------**---------------------------***------------<br>
<?php
return array(
//'配置项'=>'配置值'
'DEFAULT_MODULE' => 'Admin', // 默认模块
'DEFAULT_CONTROLLER' => 'Index', // 默认控制器名称
'DEFAULT_ACTION' => 'index', // 默认操作名称
'DB_TYPE' => 'mysqli', // 数据库类型
'DB_HOST' => 'localhost', // 服务器地址
'DB_NAME' => 'thinkphp0421', // 数据库名
'DB_USER' => 'root', // 用户名
'DB_PWD' => 'root', // 密码
'DB_PORT' => '3306', // 端口
'DB_FIELDS_CACHE' => true, // 启用字段缓存
'URL_MODEL' => 0,// 0 普通模式, 1, pathinfo模式 ,2. rewirte模式 3. 兼容模式
'SHOW_PAGE_TRACE' => true, //打开Trace Page 调试页
// 'TMPL_ENGINE_TYPE' =>'smarty'
);
----------**-----------------------**------- <br>
2. 前端代码 /tp-ceshi/Application/Admin/View/Goods/edit.html
<!-- $Id: brand_info.htm 14216 2008-03-10 02:27:21Z testyang $ -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>ECSHOP 管理中心 - {$meta_title} </title>
<meta name="robots" content="noindex, nofollow">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="__CSS__/general.css" rel="stylesheet" type="text/css" />
<link href="__CSS__/main.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>
<span class="action-span"><a href="brandList.html">商品商品</a></span>
<span class="action-span1"><a href="#">ECSHOP 管理中心</a></span>
<span id="search_id" class="action-span1"> - {$meta_title} </span>
<div style="clear:both"></div>
</h1>
<div class="main-div">
<form method="post" action="{:U()}" enctype="multipart/form-data" >
<table cellspacing="1" cellpadding="3" width="100%">
<tr>
<td class="label">商品名称</td>
<td>
<input type="text" name="goods_name" maxlength="60" value="{$goods->goods_name}" />
<span class="require-field">*</span>
</td>
</tr>
<tr>
<td class="label">商品价格</td>
<td>
<input type="text" name="goods_price" value="{$goods:goods_price}" />
</td>
</tr>
<tr>
<td class="label">商品数量</td>
<td>
<input type="text" name="goods_number" value="{$goods_number}" />
</td>
</tr>
<tr>
<td class="label">商品描述</td>
<td>
<textarea name="goods_introduce" cols="60" rows="4" ></textarea>
</td>
</tr>
<tr>
<td colspan="2" align="center"><br />
<input type="submit" class="button" value=" 确定 " />
<input type="reset" class="button" value=" 重置 " />
</td>
</tr>
</table>
</form>
</div>
<div id="footer">
共执行 1 个查询,用时 0.018952 秒,Gzip 已禁用,内存占用 2.197 MB<br />
版权所有 © 2005-2012 上海商派网络科技有限公司,并保留所有权利。</div>
</body>
</html>
------------------------***-------------------------**----------------<br>
3.模型 /tp-ceshi/Application/Admin/Model/GoodsModel.class.php
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 14-6-23
* Time: 下午2:08
*/
namespace Admin\Model;
use Think\Model;
class GoodsModel extends Model{
}
---------------------**---------------------------------***----------------------<br>
4. 控制器 /tp-ceshi/Application/Admin/Controller/GoodsController.class.php
<?php
namespace Admin\Controller;
use Think\Controller;
class GoodsController extends Controller{
public function add(){
if(IS_POST){
$goodsModel = D('Goods');
$goodsModel->create();
if($goodsModel->add(I('post'))){
$this->success('保存成功',U('index'));
}else{
$this->error('保存失败!'.$goodsModel->getError());
}
}else{
$this->display('edit');
}
}
}
-----------------------**---------------------------------**---------------------<br>
5. 数据库 thinkphp0421 ---> goods.sql
数据库
/*
Navicat MySQL Data Transfer
Source Server : root
Source Server Version : 50540
Source Host : localhost:3306
Source Database : thinkphp0421
Target Server Type : MYSQL
Target Server Version : 50540
File Encoding : 65001
Date: 2015-11-22 05:06:33
*/
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for goods
-- ----------------------------
DROP TABLE IF EXISTS `goods`;
CREATE TABLE `goods` (
`goods_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增id',
`goods_name` varchar(128) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '商品名称',
`goods_price` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '价格',
`goods_number` int(11) NOT NULL DEFAULT '100' COMMENT '数量',
`goods_introduce` text COLLATE utf8_unicode_ci COMMENT '详细介绍',
`goods_big_img` varchar(128) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '商品图片',
`goods_small_img` varchar(128) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '商品小图',
`goods_create_time` int(11) NOT NULL DEFAULT '0' COMMENT '添加时间',
`goods_last_time` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`goods_id`)
) ENGINE=InnoDB AUTO_INCREMENT=56 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='商品表';
-- ----------------------------
-- Records of goods
-- ----------------------------
INSERT INTO `goods` VALUES ('1', '1', '0.00', '100', '1', '1', '1', '0', '0');
INSERT INTO `goods` VALUES ('2', '2', '0.00', '2', '1', '1', '1', '0', '0');
-------------------**---------------------------***------------<br>
相关文章推荐
- thinphp3.2 表格案例
- php调试JS输出变量
- php命令行(cli)模式下报require 加载路径错误的解决方法
- 3种php生成唯一id的方法
- php生成4位数字验证码的实现代码
- PHP如何通过AJAX方式实现登录功能
- php执行msyql脚本 sql文件
- 【转】PHP常用工具类大全
- OLAP、OLTP的介绍和比较 via csdn
- yhdsir@function:php
- ThinkPHP 的URL重写时遇到No input file specified的解决方法
- PHP入门(9)-命名空间(namespace)
- PHP7 RC7 Release对比PHP5.6快速排序20000数据性能体验以及新语法尝鲜
- yii2引入第三方类
- PHP 源码编码标准
- 【工具】Netperf 的使用
- PHP入门(8)-魔术变量
- PHP之路
- php字符串处理函数大全
- Yii2 百度编辑器小部件