Forum Moderators: open

Message Too Old, No Replies

Mysql: Canceling duplicate entries

Syntax needed

         

russgri

4:51 am on May 18, 2006 (gmt 0)

10+ Year Member



What is the syntax to rectify this error?

user error: Duplicate entry 'modules/playlist/playlist.module' for key 1
query: INSERT INTO system (name, description, type, filename, status, throttle, bootstrap) VALUES ('playlist', 'Enables the creation of playlists, which contain audio tracks.', 'module', 'modules/playlist/playlist.module', 1, 1, 0) in /home/westernc/public_html/includes/database.mysql.inc on line 66.

txbakers

2:04 pm on May 18, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



before you write the insert, run a query to see if the key field is already in there.

if not, run the insert.
if it is there, send the user a message.

siMKin

1:48 pm on May 19, 2006 (gmt 0)

10+ Year Member



before you write the insert, run a query to see if the key field is already in there.

if not, run the insert.
if it is there, send the user a message.

It's probably faster to just do the insert and generate a custom error when it fails (of course you have to check for the error-code to make sure it's not another type of error). Saves you one query :-)

in php i would do this:


$query = "INSERT INTO table (bla,etc) VALUES (1,2)";
if (!mysql_query($query))
{
if (mysql_errno() == "1062")
// duplicate entry
else
die("The query failed<br>\n".$query."<br>\n".mysql_error());
}
else
{
// insert was succesful
}