<p>I'm dealing with a MySQL table that defines the JobName column as UNIQUE.  If somebody tries to save a new Job to the database using a JobName that is already in the database, MySQL throws a warning.</p>

<p>I would like to be able to detect this warning, just like an error, in my PHP script and deal with it appropriately.  Ideally I would like to know what kind of warning MySQL has thrown so that I can branch the code to handle it.</p>

<p>Is this possible?  If not, is it because MySQL doesn't have this ability, PHP doesn't have this ability, or both?</p>

First, you should
turn warnings off
so that your visitors don't see your
MySQL
errors. Second, when you call
```
mysql_query()
```
, you should check to see if it returned false. If it did, call
```
mysql_errno()
```
to find out what went wrong. Match the number returned to the error codes on
this page
.
It looks like this is the error number you're looking for:
Error: 1169 SQLSTATE: 23000 (ER_DUP_UNIQUE)
Message: Can't write, because of unique constraint, to table '%s'