![]() |
duplicate entry error - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: duplicate entry error (/showthread.php?tid=14058) |
duplicate entry error - El Forum - 12-16-2008 [eluser]crumpet[/eluser] Is there a way to display your own duplicate entry error without having to do an extra query to check if the insert you are making is duplicate? Instead of the user seeing this An Error Was Encountered Error Number: 1062 Duplicate entry '1-100110103401' for key 1 I want them to see something like, "You already added that" Do i need to do a query before my insert statement to check if the insert is possible? duplicate entry error - El Forum - 12-16-2008 [eluser]Armchair Samurai[/eluser] If you're only using MySQL and portability is not an issue, I'd look into INSERT IGNORE and INSERT ON DUPLICATE KEY UPDATE. For example, you could do something like this: Code: $sql = "INSERT IGNORE INTO this_table (id, data) duplicate entry error - El Forum - 01-09-2009 [eluser]learnq[/eluser] I thing its late reply ..but if some one want to show user friendly error message trun off the debuging in config/database.php $db['default']['db_debug'] = FALSE; and than .. as said ...like ... return $this->db->affected_rows() == 1 ? TRUE : FALSE; Hope it help others. duplicate entry error - El Forum - 01-09-2009 [eluser]Phil Sturgeon[/eluser] That or a Validation callback function. duplicate entry error - El Forum - 04-23-2012 [eluser]Unknown[/eluser] I have the same problem, and then I try this this is the view Code: <form action="insert_data" method="post"> this is the controller code Code: function insert_data() and this is the model Code: //the function to check whether the data inserted by user is already exists or not with this, you don't have to set the database config Code: $db['default']['db_debug'] = TRUE Code: $db['default']['db_debug'] = FALSE #sorry if my english is bad, I hope this will help ![]() |