我现在做的页面,在列表页面中,点击修改的时候,弹出修改页面,里面有当前选中项的修改信息,现在问题是我点修改时出现的是这个页面,里面没数据,求高手解答,哪里错了,应该怎么改?
页面view的代码如下:
列表页面:
<html>
<head>
<title><?php echo $title;?></title>
<script type="text/javascript">
</script>
</head>
<body>
<div style="background-color: blue;color:white;
text-align: center;font-size: 30px" ><?php echo $headLine;?></div>
<form id="admin"
action="http://dev.test.cn/index.php/admin"
name="admin" method="post">
<table align="center">
<tr style="background-color: blue;color:white;">
<td width="10%">id</td>
<td width="10%">用户名</td>
<td width="10%">密码</td>
<td width="10%">性别</td>
<td width="15%">email</td>
<td width="10%">电话</td>
<td width="15%">地址</td>
<td width="25%">编辑</td>
</tr>
<?php foreach ($users as $user):?>
<tr>
<td width="10%" id="id" ><?php echo $user->id;?></td>
<td width="10%"><?php echo $user->name;?></td>
<td width="10%"><?php echo $user->pwd;?></td>
<td width="10%"><?php echo $user->sex;?></td>
<td width="10%"><?php echo $user->email;?></td>
<td width="10%"><?php echo $user->phone;?></td>
<td width="10%"><?php echo $user->address;?></td>
<td width="25%">
<input type="button" value="删除"
id="delete" name="delete"/>
<a id="update"
>修改</a>
</td>
</tr>
<?php endforeach;?>
</table>
</form>
</body>
</html>
修改页面:
<html>
<head>
<title>修改用户信息</title>
</head>
<body>
<div style="background-color: blue;color:white;
text-align: center;font-size: 30px" >修改用户信息</div>
<p align="center">用户信息(*为必填项)</p>
<form name="registerForm" action=
"http://dev.test.cn/index.php/update/update"
method="post">
<?php
foreach($query as $row) : ?>
<table align="center">
<tr>
<input type="hidden" name="id" value="<?php echo $row->id;?>" />
<td>用户名:</td>
<td><input type="text" name="name"
id="name" value="<?php echo $row->name;?>" >*</td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" name="pwd"
id="pwd" value="<?php echo $row->pwd;?>">*</td>
</tr>
<tr>
<td>验证密码:</td>
<td><input type="password" name="v_pwd"
id="v_pwd" value="<?php echo $row->pwd;?>">*</td>
</tr>
<tr>
<td>性别:</td>
<td><input type="text" name="sex"
id="sex" value="<?php echo $row->sex;?>">
</td>
</tr>
<tr>
<td>email:</td>
<td><input type="text" name="eamil"
id="email" value="<?php echo $row->email;?>"></td>
</tr>
<tr>
<td>联系电话:</td>
<td><input type="text" name="phone"
id="phone" value="<?php echo $row->phone;?>"></td>
</tr>
<tr>
<td>地址:</td>
<td><input type="text" name="adress"
id="adress" value="<?php echo $row->address;?>"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submit"
id="submit" value="修改">
<input type="button" name="return"
onclick="javascript:history.back();"
value="返回"></td>
</tr>
</table>
</form>
<?php endforeach;?>
</body>
</html>
model如下:
function update($id,$data){
$this->db->where("id",$id);
$query=$this->db->update("user",$data);
$result=$query->result();
return $result;
}
controller中的代码:
class Update extends CI_Controller{
function __construct(){
parent::__construct();
}
function index(){
$this->load->helper("form");
$data['title']="User Update";
$data['headLine']="用户修改页面";
//$this->load->vars($data);
$this->load->helper("url");
$id = $this->uri->segment(4);
$this->load->model("mtest","",TRUE);
$data['query']=$this->mtest->getOne($id);
$this->load->view("user/update",$data);
}
function update(){
$this->load->helper("url");
$this->load->model("mtest","",TRUE);
$data=array(
'name'=> $this->input->post('name'),
'pwd'=>$this->input->post('pwd'),
'sex'=>$this->input->post('sex'),
'email'=>$this->input->post('email'),
'phone'=>$this->input->post('phone'),
'address'=>$this->input->post('address'));
$this->mtest->update($this->input->post('id'),$data);
redirect("admin","refresh");
}
}
求高手解答 |