Welcome Guest, Not a member yet? Register   Sign In
$this->db->update() --- returning errors
#1

[eluser]Dan Bowling[/eluser]
I don't see on the user guide how to determine problems when using $this->db->update().

If there is a problem, how do I know what it is?

Right now I'm using this code for my controller:

Code:
function update($id, $column)
    {
        
        $value = $this->input->get_post('value');
        
        $this->regions_model->update($column, $value, $id);
        
        if($this->db->affected_rows() > 0){
        
            $this->session->set_flashdata('flash', '<p class="success">Region updated</p>');
        
        }
        else {
            
            $this->session->set_flashdata('flash', '<p class="fail">Error! Region was not updated</p>');
            
        }
        redirect('/regions/view/' . $id, 'refresh');
    }

and this for the model:
Code:
function update($column, $value, $id)
    {
        $this->db->where('region_id', $id);
        $data = array(
            $column => $value
        );
        $this->db->update('regions', $data);
    }

The value sometimes doesn't update, and for the life of me, I can't figure out why.

I'm sure you can tell I'm pretty new at this by my code. Any feedback to help me learn is greatly appreciated.
#2

[eluser]m4rw3r[/eluser]
Try setting your log_threshold to 4, then check the log.
If that doesn't help you, check $this->db->affected_rows() and the return of update().
Also check $this->db->last_query().
#3

[eluser]Frychiko[/eluser]
Add this line of code to the controller:
Code:
$this->output->enable_profiler(TRUE);

It outputs varies things to the screen (post variables, sql queries etc.)
Then you can see the sql queries on your screen to see exactly what is going on. You can cut and paste that and plug it into phpmyadmin to find out exactly what went wrong.
#4

[eluser]Dan Bowling[/eluser]
Thanks!

Those commands are very helpful!




Theme © iAndrew 2016 - Forum software by © MyBB