0

In order to avoid a user creating duplicate data I use a UNIQUE constraint on a field. Everything works perfect until a duplicate entry; which immediately gives me an internal server error. I am using CodeIgniter for queries and check database errors using $this->db->_error_message() yet instead of being handled the program seems to exit and the error number is returned on my AJAX call. Is there another way of handling these types of errors or is it something I am doing wrong?

4
  • you might wanna post relevant code. Commented Apr 29, 2014 at 3:43
  • Sounds like an Exception gets thrown, and you neglected to catch it properly. Commented Apr 29, 2014 at 3:45
  • @CBroe What was it that threw the exception and how do I handle it? Commented Apr 29, 2014 at 3:48
  • see if you are getting any error on apache error_log or whatever webserver you are using Commented Apr 29, 2014 at 4:02

1 Answer 1

0

Inserting a duplicate will throw the exeption.

Try to catch it like this:

try
{
    // insertin the duplicate
}
catch (Exception $e)
{
    echo 'Exeption: '.  $e->getMessage();
}

More about exception handling: http://www.php.net/manual/en/language.exceptions.php

Sign up to request clarification or add additional context in comments.

2 Comments

That did not work. After the duplicate error is fired execution stops completely and the try/catch block does not do anything.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.