How to test if INSERT worked? |
[eluser]yello[/eluser]
Hi Code: $entry['state'] = $_POST['state']; If there is a duplicate entry in the insert, I want to redirect the user to my error page. Right now all they see is the CI error: Quote:An Error Was Encountered Can anyone help? Thanks ![]()
[eluser]sharpe[/eluser]
try this : $data = array('name' => $name, 'email' => $email, 'url' => $url); $str = $this->db->insert_string('table_name', $data); if($str) { ...etc }else { ... on duplicate } You have to set db debug to false or INSERT MyTable (MyKey, MyField1) VALUES (1, ‘Hi!’) ON DUPLICATE KEY UPDATE MyField1 = ‘Hi!’ WHERE MyKey = 1 see http://ellislab.com/forums/viewthread/61318/
[eluser]llbbl[/eluser]
I like to do it myself. Code: $this->db->query("INSERT INTO `databasename` SET field1='$something', field2='$something', field3='$something'"); You should check to see if the duplicate entry exists already before you insert. It doesn't have to be every field you check right just the ones that matter.
[eluser]yello[/eluser]
[quote author="sharpe" date="1191880268"]try this : ... You have to set db debug to false ... [/quote] that fixed the problem ![]()
[eluser]Derek Allard[/eluser]
A different approach would be to use $this->db->insert_id(), but I agree with the methods above that checking if it exists first is probably the way to go. |
Welcome Guest, Not a member yet? Register Sign In |