TP框架修改操作
function update()
{
$info=M("info");
$code = $_GET["code"];
if(empty($_POST))
{
$attr=$info->find($code);
$minzu=$info->table("nation")->distinct(true)->select();
$this->assign("nation",$minzu);
$this->assign("sj",$attr);
$this->display();
}
else
{
$info->create();
$code1=$_POST["Code"];
$info->Sex=$_POST["Sex"]=="男"?true:false;
$att = $info->where("code='{$code1}'")->save();
if($att)
{
$this->success("修改成功",U("main"),3);
}
else
{
$this->error("修改失败","update",3);
}
}
}
<h1>修改页面</h1> <form action="__ACTION__" method="post"> <div>代号:<input type="text" name="Code" value="<{$sj.code}>"/></div><br /> <div>姓名:<input type="text" name="Name" value="<{$sj.name}>"/></div><br /> <div>性别: <input type="text" name="Sex" value="<{$sj['sex']==true?'男':'女'}>"></option> </div><br /> <div>民族: <select name="Nation"> <foreach name="nation" item="v"> <if condition="$sj['nation']==$v['code']"> <option value="<{$v.code}>" selected="selected"><{$v.name}></option> <else/> <option value="<{$v.code}>"><{$v.name}></option> </if> </foreach> </select> </div><br /> <div>生日:<input type="text" name="Birthday" value="<{$sj.birthday}>"/></div><br /> <div><input type="submit" value="修改"/></div> </form>