PHP-------smaty 增删改查

smaty 增删改查

smarty-----main文件夹,是放php文件的--------templates文件夹是放html文件的

我们访问的页面是php页面,PHP页面需要使用smarty模板,需要把smarty模板路口文件或者叫配置文件引入。include("../init.inc.php");。这个php页面在访问是需要打出一个页面让用户看到页面的内容,所以要调用smarty对象里面的方法$smarty->display( 模板页面的名字,html);.

登陆

main-------denglu.php

 1 <?php
 2 include("../init.inc.php");
 3 $smarty->display("denglu.html");
 4
 5
 6 templates-----denglu.html
 7 <title>登陆界面</title>
 8 </head>
 9 <body>
10  <center>
11 <h1>登陆界面</h1>
12 <table width="20%" border="0" cellpadding="0" cellspacing="0">
13 <tr>
14 <form action="dengluchuli.php" method="post">
15 <tr><td style="font-size:23px">用户名</td><td><input type="text" name="yonghuming" style=" width:170px; height:28px" /></td></tr>
16 <tr><td>&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;</td></tr>
17 <tr><td>&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;</td></tr>
18 <tr><td  style="font-size:23px">密码</td><td><input type="password" name="mima" style=" width:170px; height:28px"/></td></tr>
19 <tr><td>&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;</td></tr>
20 <tr><td>&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;</td></tr>
21  </table>
22  <center><input type="submit" value="登陆" /><center>
23 </form>
24 </center>
25 </body>
26 </html>

main-------dengluchuli.php

 1 <?php
 2 session_start();    //开启session
 3 include("../DBDA.php");   //要查数据库就要引用DBDA.PHP类
 4 $db = new DBDA();
 5 $yonghuming = $_POST["yonghuming"];
 6 $mima = $_POST["mima"];
 7 $sql = "select pwd from users where uid=‘{$yonghuming}‘";    //根据密码查用户名
 8 $mima1 = $db->StrQuery($sql);    //查的是字符串,就一条数据
 9 if($yonghuming!="" && $mima!="")   //用户名和密码不能为空
10 {
11     if($mima==$mima1)  //去匹配用户传的密码和数据库查到的密码是否一致
12     {
13         $_SESSION["yonghuming"]=$yonghuming;
14         header("location:zhuyemian.php");
15     }
16     else
17     {
18            header("location:denglu.php");
19     }
20 }
21 else
22     {
23            header("location:denglu.php");
24     }

主页面

main----zhuyemian.php

 1 <?php
 2 session_start();
 3 include("../init.inc.php");
 4 include("../DBDA.php");
 5 include("page.class.php");
 6
 7 $db = new DBDA();
 8
 9 if(empty($_SESSION["yonghuming"]))
10 {
11     header("location:denglu.php");
12     exit;
13 }
14
15 $tj = " 1=1 ";
16 $name = "";
17 if(!empty($_GET["name"]))
18 {
19     $name = $_GET["name"];
20     $tj = " name like ‘%{$name}%‘ ";
21
22 }
23 $ztj = " where {$tj}";
24
25 //查出总条数
26 $szs = "select count(*) from info ".$ztj;
27 $zs = $db->StrQuery($szs);
28
29 //造分页类对象
30 $page = new page($zs,3);
31
32 $yonghuming = $_SESSION["yonghuming"];
33 //根据用户名查姓名
34 $sql = "select name from users where uid=‘{$yonghuming}‘";
35 $xingming = $db->StrQuery($sql);
36
37 //查info表
38 $sql1 = "select * from info ".$ztj.$page->limit;
39 $a = $db->Query($sql1);
40
41
42 //取分页信息
43 $xinxi = $page->fpage();
44
45 $smarty->assign("xingming",$xingming);
46 $smarty->assign("a",$a);
47 $smarty->assign("xinxi",$xinxi);
48 $smarty->assign("name",$name);
49
50
51 $smarty->display("zhuyemian.html");

templates----zhuyemian.html

 1 <title>主页面(用户管理)</title>
 2 <style type="text/css">
 3 *{ margin:0px auto; padding:0px; font-family:微软雅黑}
 4 #main{ width:1320px;}
 5 #top{ width:1320px; height:100px; background-color:#09F; line-height:100px; vertical-align:middle; color:#FFF; font-weight:bold}
 6 #neirong{ margin-top:30px}
 7 </style><!--设置垂直居中有两个条件::::垂直要设置div的高度line-height:100px;,和垂直居中居中vertical-align:middle-->
 8 </head>
 9 <body>
10 <center><h1>主页面(用户管理)</h1></center>
11 <div id="main"></div>
12 <div id="top">
13 欢迎登录:<{$xingming}>
14 </div>
15
16 <div id="neirong">
17 <form action="zhuyemian.php" method="get">
18 <div>
19     请输入姓名:
20     <input type="text" name="name" value="<{$name}>" />
21     <input type="submit" value="查询" />
22 </div>
23 </form>
24
25 <table width="100%" border="1" cellpadding="0" cellspacing="0">
26 <tr bgcolor="#00FF99">
27 <td>代号</td>
28 <td>姓名</td>
29 <td>性别</td>
30 <td>民族</td>
31 <td>出生日期</td>
32 <td>操作</td>
33 </tr>
34
35 <{foreach $a as $v}>
36 <{if $v@index%2==0}>
37 <tr>
38 <td><{$v[0]}></td>
39 <td><{$v[1]}></td>
40 <td><{$v[2]|sexname}></td>
41 <td><{$v[3]|nationname}></td>
42 <td><{$v[4]}></td>
43 <td><a href="shanchu.php?code=<{$v[0]}>" onclick="return confirm(‘确定要删除吗?‘)">删除</a>
44 <a href="xiugai.php?code=<{$v[0]}>">修改</a>
45 <input type="button" value="查看详情" />
46
47 </td>
48 </tr>
49 <{else}>
50 <tr bgcolor="#FF99FF">
51 <td><{$v[0]}></td>
52 <td><{$v[1]}></td>
53 <td><{$v[2]|sexname}></td>
54 <td><{$v[3]|nationname}></td>
55 <td><{$v[4]}></td>
56 <td><a href="shanchu.php?code=<{$v[0]}>" onclick="return confirm(‘确定要删除吗?‘)">删除</a>
57 <a href="xiugai.php?code=<{$v[0]}>">修改</a>
58 <input type="button" value="查看详情" />
59 </td>
60 </tr>
61 <{/if}>
62 <{/foreach}>
63 </table>
64
65 <div><{$xinxi}></div>
66 </div>
67
68 <div><a href="tianjia.php">添加数据</a><div>
69 </body>
70 </html>

添加页面

main-----tianjai.php

 1 <?php
 2 include("../init.inc.php");
 3 include("../DBDA.php");
 4
 5  $db= new DBDA();
 6  $sql = "select * from nation";
 7  $attr = $db->Query($sql);
 8 $smarty->assign("minzu",$attr);
 9 $smarty->display("tianjia.html");
10
11 templates----tianjai.html
12 <title>添加数据</title>
13 </head>
14 <body>
15 <h1>添加数据</h1>
16 <form action="tianjiachuli.php" method="post">
17 <div>代号:<input type="text" name="daihao" /></div>
18 <div>姓名:<input type="text" name="xingming" /></div>
19 <div>性别:<input type="radio" name="xingbie" value="1" checked="checked"/>男
20 <input type="radio" name="xingbie" value="0"/>女</div>
21 <div>民族:
22 <select name="minzu">
23 <{foreach $minzu as $v}>
24 <option value="<{$v[0]}>"><{$v[1]}></option>
25 <{/foreach}>
26 </select>
27 </div>
28 <div>出生日期:<input type="text" name="chusheng" /></div>
29 <div><input type="submit" value="添加数据" /></div>
30 </form>
31 </body>
32 </html>
33
34 main-----tianjiachuli.php
35  <?php
36 include("../DBDA.php");
37 $db = new DBDA();
38 $daihao = $_POST["daihao"];
39 $xingming = $_POST["xingming"];
40 $xingbie = $_POST["xingbie"];
41 $minzu = $_POST["minzu"];
42 $chusheng = $_POST["chusheng"];
43
44 $sql = "insert into info values(‘{$daihao}‘,‘{$xingming}‘,‘{$xingbie}‘,‘{$minzu}‘,‘{$chusheng}‘)";
45
46 if($db->Query($sql,0))
47 {
48     header("location:zhuyemian.php");
49
50 }
51 else
52 {
53     echo "添加失败";
54
55     }

修改页面

main----xiugai.php

 1 <?php
 2 include("../init.inc.php");
 3 include("../DBDA.php");
 4
 5 $db = new DBDA();
 6 $sql = "select * from nation";
 7 $attr = $db->Query($sql);
 8
 9 $code = $_GET["code"];
10 $sxx = "select * from info where code=‘{$code}‘";
11 $sxx = $db->Query($sxx);
12 //var_dump($sxx);
13 $daihao = $sxx[0][0];
14 $xingming = $sxx[0][1];
15 $xingbie = $sxx[0][2];
16 $minzu = $sxx[0][3];
17 $chusheng = $sxx[0][4];
18
19 $smarty->assign("minzu1",$attr);
20
21 $smarty->assign("daihao",$daihao);
22 $smarty->assign("xingming",$xingming);
23 $smarty->assign("xingbie",$xingbie);
24 $smarty->assign("minzu",$minzu);
25 $smarty->assign("chusheng",$chusheng);
26
27 $smarty->display("xiugai.html");

templates -----xiugai.html

 1 <title>无标题文档</title>
 2 </head>
 3 <body>
 4 <center>
 5 <h1>修改数据</h1>
 6 <form action="xiugaichuli.php" method="post">
 7 <div> <input type="hidden" name="daihao" value="<{$daihao}>"/></div>
 8 <div>姓名:<input type="text" name="xingming" value="<{$xingming}>"/></div>
 9 <br />
10 <div>性别:
11 <{if $xingbie}>
12 <input type="radio" name="xingbie" value="1" checked="checkde" />男
13 <input type="radio" name="xingbie" value="0" />女</div>
14 <{else}>
15 <input type="radio" name="xingbie" value="1" />男
16 <input type="radio" name="xingbie" value="0" checked="checked"/>女</div>
17 <{/if}>
18 <br />
19
20 <div>民族:
21 <select name="minzu">
22 <{foreach $minzu1 as $v}>
23 <{if $minzu==$v[0]}>
24 <option value="<{$v[0]}>" selected="selected"><{$v[1]}></option>
25 <{else}>
26 <option value="<{$v[0]}>"><{$v[1]}></option>
27 <{/if}>
28 <{/foreach}>
29 </select>
30 </div>
31 <br />
32 <div>出生日期:<input type="text" name="chusheng" value="<{$chusheng}>"/></div>
33 <br />
34 <div><input type="submit" value="修改数据" /></div>
35 </form>
36 </center>
37 </body>
38 </html>

main-----xiugaichuli.php

 1 <?php
 2 include("../DBDA.php");
 3 $db = new DBDA();
 4 $daihao = $_POST["daihao"];
 5 $xingming = $_POST["xingming"];
 6 $xingbie = $_POST["xingbie"];
 7 $minzu = $_POST["minzu"];
 8 $chusheng = $_POST["chusheng"];
 9
10 $sql = "update info set Name=‘{$xingming}‘,Sex={$xingbie},Nation=‘{$minzu}‘,Birthday=‘{$chusheng}‘ where Code=‘{$daihao}‘";
11  $db->Query($sql,0);
12
13  header("location:zhuyemian.php");

删除页面

main------shanchu.php

1 <?php
2 include("../DBDA.php");
3 $db= new DBDA();
4 $code = $_GET["code"];
5
6 $sql = "delete from info where Code=‘{$code}‘";
7 $db->Query($sql,0);
8 header("location:zhuyemian.php");
时间: 2024-12-15 06:28:27

PHP-------smaty 增删改查的相关文章

Python 模拟SQL对文件进行增删改查

1 #!/usr/bin/env python 2 # _*_ coding:UTF-8 _*_ 3 # __auth__: Dalhhin 4 # Python 3.5.2,Pycharm 2016.3.2 5 # 2017/05/15 6 7 import sys,os 8 9 def where(dbfile,where_list): #条件是一个list 10 11 def and_or_where(sub_where_list): 12 '''获取and或同时含有and.or关键字的条

【黑马Android】(04)数据库的创建和sql语句增删改查/LinearLayout展示列表数据/ListView的使用和BaseAdater/内容提供者创建

数据库的创建和sql语句增删改查 1. 加载驱动. 2. 连接数据库. 3. 操作数据库. 创建表: create table person( _id integer primary key, name varchar(20), age integer ); 添加: insert into person(name, age) values('lisi', 19); 删除: delete from person where _id = 1; 修改: update person set name =

ssm框架搭建+easyui增删改查实现

闲来无事,看了看别人的博客文档也跟着敲了敲,特地记录下来,方便以后学习: spring版本:4.0.6 mybatis版本:3.2.5 所有jar包打包下载:http://pan.baidu.com/s/1qLEaU 1.项目目录结构 其中,controller包下存放控制层文件,dao下存放各个model类相关的数据库操作接口,entity下放置各种model类,mappers下放置各个dao对应的映射文件,service服务层就不说了,放置各种service接口,impl是其具体实现类. 2

【Android】Sqlite数据库增删改查

Android系统内置一个Sqlite数据库,如果app需要使用Sqlite数据库数据库存储数据,Android会为此app生成一个.db文件.这个数据库在data/data/<package_name>/databases里面,其中<package_name>为该安卓app的工程包名,这个目录必须root后才能看到.在Windows,单机的应用程序,存储数据,基本放到一个文件里面,正如游戏的存档,基本就是把当前的游戏状态存到一个用户很难找到的文件里面.每次存档读档就是一个从这个存

夺命雷公狗---Thinkphp----12之文章的增删改查(图片上传和关联查询)

我们由于表分析的不够完善,所以我们来加多一个tid的字段,到时候主要目的是为了更好的遍历出文章是属于那个分类下的,表如下所示: 那么下一步我们就开始创建一个ArticleController.class.php的控制器,用来管理文章的增删改查操作,所以我们开始第一步来实现文章的添加,我们先来实现他的增加功能: public function add(){ if(IS_POST){ $data['title'] = I('title'); $data['tid'] = I('tid'); $dat

MyBatis增删改查模板

1. 首先,和Spring整合一下 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springfra

用基本数据结构修改后的学生信息管理系统(增删改查)

package com.xt.student.system; //创建学生类存放信息 public class Student {//声明变量private String stuNo; private String stuName; private String gender; private int age; private int score; //对变量进行封装 public String getStuNo() {return stuNo;} public void setStuNo(St

第二周作业__增删改查

html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption

zookeeper基本命令,增删改查

zookeeper被广泛的使用,由于项目中用到了dubbo框架,所以今天也来简单分享一下zookeeper的简单命令,来查询服务和节点信息,不说了,直接来增删改查命令. -h命令: [zk: localhost:2189(CONNECTED) 35] h ZooKeeper -server host:port cmd args addauth scheme auth close config [-c] [-w] [-s] connect host:port create [-s] [-e] [-