![]() |
codeigniter ajax database error handling - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6) +--- Forum: CodeIgniter 3.x (https://forum.codeigniter.com/forumdisplay.php?fid=17) +--- Thread: codeigniter ajax database error handling (/showthread.php?tid=79350) |
codeigniter ajax database error handling - jackey - 06-01-2021 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){ RE: codeigniter ajax database error handling - includebeer - 06-05-2021 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-build-a-basic-web-application-with-codeigniter-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/libraries/validation.html#available-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... |