Welcome Guest, Not a member yet? Register   Sign In
unable to update record
#1
Wink 

I am new to web development and trying to learn the codeigniter. I am following tutorial ever thing is ok. but the edit / update page is not working. May be this is a stupid topic but I am having problem to learn MVC concept. any other suggestion that I can learn the MVC.

here is controller :

Code:
     public function update_student_view() {
        $this->load->helper('form');
        $roll_no = $this->uri->segment('3');
        $query = $this->db->get_where("stud",array("roll_no"=>$roll_no));
        $data['records'] = $query->result();
        $data['old_roll_no'] = $roll_no;
        $this->load->view('Stud_edit',$data);
     }
 
     public function update_student(){
        $this->load->model('Stud_Model');
            
        $data = array(
           'roll_no' => $this->input->post('roll_no'),
           'name' => $this->input->post('name')
        );
            
        $old_roll_no = $this->input->post('old_roll_no');
        $this->Stud_Model->update($data,$old_roll_no);
            
        $query = $this->db->get("stud");
        $data['records'] = $query->result();
        $this->load->view('Stud_view',$data);
        
     }

here is model:


Code:
     public function update($data,$old_roll_no) {
        $this->db->set($data);
        $this->db->where("roll_no", $old_roll_no);
        $this->db->update("stud", $data);
     }


here is edit view

Code:
<!DOCTYPE html>
<html lang = "en">

  <head>
     <meta charset = "utf-8">
     <title>Students Example edit</title>
  </head>
    
  <body>
     <form method = "" action = "">
        
        <?php
           echo form_open('Stud_controller/update_student');
           echo form_hidden('old_roll_no',$old_roll_no);
           echo form_label('Roll No.');
           echo form_input(array('id'=>'roll_no','name'=>'roll_no','value'=>$records[0]->roll_no));
           echo "<br/>";
                
           echo form_label('Name');
           echo form_input(array('id'=>'name','name'=>'name','value'=>$records[0]->name));
           echo "<br/>";
                
           echo form_submit(array('id'=>'submit','value'=>'Edit'));
           echo form_close();
            echo $this->db->last_query();
        ?>
            
     </form>
  </body>
    
</html>

here is stud_view view


Code:
<!DOCTYPE html>
<html lang = "en">

  <head>
     <meta charset = "utf-8">
     <title>Students Example</title>
  </head>
    
  <body>
     <a href = "<?php echo base_url();?>index.php/stud/add_view">Add</a>
        
     <table border = "1">
        <?php
           $i = 1;
           echo "<tr>";
           echo "<td>Sr#</td>";
           echo "<td>Roll No.</td>";
           echo "<td>Name</td>";
           echo "<td>Edit</td>";
           echo "<td>Delete</td>";
           echo "<tr>";
                
           foreach($records as $r) {
              echo "<tr>";
              echo "<td>".$i++."</td>";
              echo "<td>".$r->roll_no."</td>";
              echo "<td>".$r->name."</td>";
              echo "<td><a href = '".base_url()."index.php/stud/edit/"
                 .$r->roll_no."'>Edit</a></td>";
              echo "<td><a href = '".base_url()."index.php/stud/delete/"
                 .$r->roll_no."'>Delete</a></td>";
              echo "<tr>";
           }
        ?>
     </table>
        
  </body>
    
</html>
Reply


Messages In This Thread
unable to update record - by nadeem14375 - 07-27-2016, 11:16 AM
RE: unable to update record - by mwhitney - 07-27-2016, 11:57 AM
RE: unable to update record - by nadeem14375 - 07-27-2016, 12:18 PM
RE: unable to update record - by nadeem14375 - 07-27-2016, 12:20 PM
RE: unable to update record - by mwhitney - 07-28-2016, 10:35 AM
RE: unable to update record - by Wouter60 - 07-28-2016, 08:46 AM
RE: unable to update record - by jaynarayan - 07-30-2016, 10:36 AM
RE: unable to update record - by nadeem14375 - 07-30-2016, 11:14 AM
RE: unable to update record - by InsiteFX - 07-30-2016, 11:37 AM
RE: unable to update record - by nadeem14375 - 07-30-2016, 11:52 AM
RE: unable to update record - by nadeem14375 - 07-30-2016, 12:37 PM
RE: unable to update record - by Wouter60 - 07-30-2016, 11:08 PM
RE: unable to update record - by nadeem14375 - 07-31-2016, 02:18 AM
RE: unable to update record - by Wouter60 - 07-31-2016, 05:50 AM



Theme © iAndrew 2016 - Forum software by © MyBB