CodeIgniter Forums
Failed to Update data inside Input field - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Model-View-Controller (https://forum.codeigniter.com/forumdisplay.php?fid=10)
+--- Thread: Failed to Update data inside Input field (/showthread.php?tid=61603)



Failed to Update data inside Input field - s4dman - 04-29-2015

I'm trying to update my data inside INPUT FIELD using a UPDATE Button. In the image below, I'll type new data in the field and press Edit button and my DB will be updated.

[Image: pjJf6PV.jpg]

But I'm stuck in where clause.

$this->output->enable_profiler(TRUE); was showing that in query WHERE 'id'=NULL.  My query can't specify the id field.

*Called the model inside construct already.
view :
PHP Code:
<?php if(isset($records)) : foreach($records  as $row): ?>
<?php  echo form_open
('main/update'?>
 
<td> <input type="text" name="edit_tname" value="<?php echo $row->tname ;?>"/> </td>
<td> <input type="text" name="edit_time" value="<?php echo $row->time?>" /></td>

<td> <input type="submit" value="Edit"> </td>

<?php echo form_close();?>

<?php endforeach; ?>

controller :
PHP Code:
public function update_task()
 
       {
 
          $this->model_users->updateM();
 
          redirect('main');
 
       

model:
PHP Code:
public function updateM()
 
           {
 
               $updated_data = array(
 
                   'tname'=> $this->input->post('edit_tname'),
 
                   'time'=> $this->input->post('edit_time')
 
                   );
 
                   
                $this
->db->where('id'$this->uri->segment(3));
 
               $this->db->update('tasks'$updated_data);
 
           



RE: Failed to Update data inside Input field - gadelat - 04-30-2015

put the id in hidden input, or as part of form_open url


RE: Failed to Update data inside Input field - Wouter60 - 04-30-2015

As Gadelat said: add a hidden field.
Like this:
Code:
<?php echo form_hidden('id', $row->id);?>

In your controller, read the value:
Code:
$id = $this->input->post('id');



RE: Failed to Update data inside Input field - s4dman - 04-30-2015

Yap it worked, Thanks Smile