I\'ve tried other answers similar to mine but in vain.
Here is the code.
Use mysql_error()
Returns the text of the error message from previous MySQL operation
http://www.php.net/manual/en/function.mysql-error.php