如何使用codelgniter更新数据库中的记录?

时间:2015-09-25 10:13:37

标签: php html codeigniter

enter image description here我正在尝试使用codelgniter更新数据库中的记录,但它无法正常工作。请检查代码并协助我在哪里错了?请检查错误。enter image description here请帮助我。

控制器代码

public function update()
{

$id=$this->uri->segment(3);

$this->load->model('model_edit');
$a=$this->model_edit->update($id);


$data['userId']= $a->userId;
$data['date']= $a->date;
$data['firtsname']= $a->firtsname;
$data['middlename']= $a->middlename;
$data['lastname']= $a->lastname;
$data['mobileno']= $a->mobileno;

$data['landline']= $a->landline;
$data['address']= $a->address;
$data['city']= $a->city;
$data['locality']= $a->locality;
$data['email']= $a->email;


$this->load->view("index",$data);

}

型号代码

public function update($userId)

    {

$query = $this->db->get_where('add_user', array('id' => $userId));

      return $query;
    }

查看代码

<body>
 <div class="container">

 <div class="tab-center">
    <div id="tabs">

  <ul>
    <li><a href="#tabs-1">Add User</a></li>
    <li><a href="#tabs-2">User List</a></li>

  </ul>
  <div id="tabs-1">
    <div class="title">
    <p><strong>ADD USER</strong></p>
    </div>
<?php echo form_open("Welcome/add_user"); ?>

    <input type="text" name="userId" placeholder="USER ID" style="width:500px">&nbsp;
    <input type="date" name="date" style="width:500px">


    <input type="text" name="firtsname" placeholder="FIRST NAME" style="width:330px">&nbsp;
    <input type="text" name="middlename" placeholder="MIDDLE NAME" style="width:330px">&nbsp;
    <input type="text" name="lastname" placeholder="LAST NAME" style="width:330px">&nbsp;

    <input type="text" name="mobileno" placeholder="ENTER MOBILE NO." style="width:500px">&nbsp;
    <input type="text" name="landline" placeholder="LANDLINE No." style="width:500px">
    <textarea name="address" placeholder="ENTER ADDRESS"></textarea>

    <input type="text" name="city" placeholder="CITY" style="width:500px">&nbsp;
    <input type="text" name="locality" placeholder="LOCALITY" style="width:500px">
    <input type="text" name="email" placeholder="ENTER EMAIL" style="width:1010px"></br>

  <input type="submit" class="submit" name="SUBMIT">
<?php echo form_close(); ?>
  </div>

  <div id="tabs-2">

<div  class="table-responsive">
   <table class="table table-bordered" >  
        <thead>
         <tr>  


          <td><b></b></td>
          <td><b></b></td>
            <td><b>userId</b></td>  

            <td><b>firtsname</b></td>  

            <td><b>lastname</b></td>  
            <td><b>mobileno</b></td>  


            <td><b>address</b></td> 
            <td><b>city</b></td>  

            <td><b>email</b></td> 

         </tr> 
          </thead>

         <?php  
         foreach ($user->result() as $row)  
         {  
            ?>

              <tbody><tr >  
        <td><a href="<?php echo site_url('Welcome/delete/'.$row->userId)?>"><img src="http://localhost/CRM/img/delete.png" name="delete_image" ></a></td>
        <td><a href="<?php echo site_url('Welcome/update/'.$row->userId)?>"><img src="http://localhost/CRM/img/edit.png" name="edit_image" ></a></td>
            <td><?php echo $row->userId;?></td>  

            <td><?php echo $row->firtsname;?></td>  

            <td><?php echo $row->lastname;?></td>  
            <td><?php echo $row->mobileno;?></td>  


            <td><?php echo $row->address;?></td> 
            <td><?php echo $row->city;?></td> 

            <td><?php echo $row->email;?></td> 

            </tr>   </tbody> 
         <?php }  

         ?>  

   </table>  
  </div>

    </div>

1 个答案:

答案 0 :(得分:0)

试试这个

    function update($id, $data = array()) {
        $this->db->get_where('add_user', array('id' => $userId))->result_array();
    }