用户
 找回密码
 入住 CI 中国社区
搜索
查看: 1955|回复: 2
收起左侧

[HELP] 修改页面的数据为什么老是不对

[复制链接]
发表于 2014-1-4 10:43:26 | 显示全部楼层 |阅读模式
10CI币
我现在做的页面,在列表页面中,点击修改的时候,弹出修改页面,里面有当前选中项的修改信息,现在问题是我点修改时出现的是这个页面,里面没数据,求高手解答,哪里错了,应该怎么改?

页面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");
  }
}
求高手解答

发表于 2014-1-5 23:28:52 | 显示全部楼层
看提示是说你在调用 一个不存在的对象的方法。。。
你这个写法有很大的问题。。
第一,你的类名竟然叫update...这在ci里不知道能不能用,就算能用,命名是很不科学 的。
第二,php4及之前,类同名的方法认定为构造函数,而php5为了向上兼容,也是这么做的。而你的类是update,里面又有不是想做为构造函数的update方法。。。
第三,你的<a id="update">编辑</a>这种,怎么能跳得过去的。。。是用了什么js方法么,呵呵。
回复

使用道具 举报

 楼主| 发表于 2014-1-6 09:19:42 | 显示全部楼层
哦,谢谢指正
回复

使用道具 举报

本版积分规则