codeigniter ajax database error handling |
When I try to add duplicate entry, it give error like this.
I want to the error "Duplicate entry '[email protected]' for key 'email' " to be visible in my view page inside div tag as alert-danger Can any one pls help me Code: ///////////View//////// PHP Code: function add_temp_student() //////////////controller////////// PHP Code: public function add_temp_student() { PHP Code: public function model_add_temp_student($data){
You need to validate your data before you try to insert in the database. This way you catch the error and display it to the user. You need to do this to prevent the database from throwing an error.
I have a tutorial on how to use the validation class: https://includebeer.com/en/blog/how-to-b...r-4-part-6 You just need to adjust what rule you need. In your case you will want the is_unique rule: http://codeigniter.com/user_guide/librar...able-rules I just saw this was posted in the CI3 forum. There's also a validation class available in CI3, I just don't have any example on how to use it...
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/ |
Welcome Guest, Not a member yet? Register Sign In |