Forum Moderators: coopster

Message Too Old, No Replies

MySQL Insert with Unique Key

how to display message when data already exists

         

mn1dbp

11:08 pm on Sep 16, 2004 (gmt 0)

10+ Year Member



I have a insert PHP page which puts data into MySQL database.

I have an ID colum which is the primary key and i also have one of the other Columns as a Unique ID to stop people adding duplicates. This works fine and if this column is a duplicate the data is not added to the database. However whether data is added or not you get the same message after you complete the form.

What i want is different messages so that when you try and enter a duplicate it returns an error message possibly showing you the record that already exists.

figment88

11:21 pm on Sep 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



mysql_errno() returns the last error from a mysql operation. You can test that is zero before giving the everything is ok message.

If you want specific messages for different classes of problems, you can use the error code
[dev.mysql.com...]

or the php function mysql_error().