Error Number: 1062 HELP |
[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
[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)
[eluser]maniking[/eluser]
Thanks for replay I will try now this code... And how I can make secure that $_POST data validation? Thanks
[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
[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-gui...ation.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. |
Welcome Guest, Not a member yet? Register Sign In |