CodeIgniter Forums
handle error insert database - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: handle error insert database (/thread-25970.html)



handle error insert database - El Forum - 01-02-2010

[eluser]tnathos[/eluser]
hi, i have a table whit 3 fields, field 1 and 2 are the primary key.. i make a insert in the database and works fine.

I need know if the data what send the user exits in the database previuly.. but i dont like make before a insert an select...

I think.. if i try insert.. the db tell me what the data exits.. and i dont insert.. (validate the primary)

But i have a problem.. when make the second insert.. show me a error in text!! and cant catch..

any can help me?

Code:
$set_fav = array (
        'id_usuario' => $this->session->userdata('id'),
        'id_proceso' => $this->session->userdata('id_proceso'),
        'fecha' => date('Y-m-d'));
            
        if($this->db->insert('table',$set_fav))    
            return true; // ok new data
        else
            return false; // fail insert.. doble data for prmary key