![]() |
Error Number: 1062 HELP - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: Error Number: 1062 HELP (/showthread.php?tid=60660) |
Error Number: 1062 HELP - El Forum - 05-22-2014 [eluser]maniking[/eluser] Hello Guyz Need Help This is error when i try to add duplicate country names. Error Number: 1062 Duplicate entry 'italy ' for key 'Country_Name_UNIQUE' INSERT INTO `country` (`fkContinent_id`, `Country_Name`, `Country_ShortName`, `Country_Url`, `Country_PageTitle`, `Country_MetaKeywords`, `Country_MetaDescription`, `Country_PageContent`, `Country_Ext`) VALUES ('11', 'italy ', '', 'italy-', '', '', '', '', '') Filename: C:\xampp\htdocs\score\system\database\DB_driver.php Line Number: 330 My Controller : Code: function add() i wanted to print this error msg on my page to avoid this sql error on page i m new please help Thanks Error Number: 1062 HELP - El Forum - 05-23-2014 [eluser]CroNiX[/eluser] Turn off db_debug in database config and use Code: $this->db->_error_message(); You are also doing something very dangerous by inserting $_POST directly with no data validation. Very insecure. All of CI's db "write" type statements (insert/update/etc) return a boolean FALSE if there is an error. Code: if ($this->db->insert("country", $_POST) === FALSE) Error Number: 1062 HELP - El Forum - 05-23-2014 [eluser]maniking[/eluser] Thanks for replay I will try now this code... And how I can make secure that $_POST data validation? Thanks Error Number: 1062 HELP - El Forum - 05-23-2014 [eluser]maniking[/eluser] I tryed this code but still same error coming.. My Controller : Code: function add() My View Page Where i Enter Data : Code: <form method="post" enctype="multipart/form-data"> Thanks Error Number: 1062 HELP - El Forum - 05-23-2014 [eluser]CroNiX[/eluser] Did you turn db_debug off? db_debug captures and displays all db errors automatically, so you need to turn it off if you want to handle them manually. For validation of form data: http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html You are running the same query 2x now. It would be much better to check if the value exists first in the db before trying to insert a new one, rather than relying on errors. |