-1

I know this is kinda dumb, but how do we prevent duplicate entries in sql? i had this php system that inserts registration record and when I tried inserting new record, it works, but when I go back to the insert page and Click the "Add" button again, the system inserts the same record as "new" and doesnt recognize it as duplicate, my primary key is the id which is auto incremented. my goal is to have some sort of "solution" aside from changing the primary key coz it would definitely ruin my system. Thanks!

  • 1
    Table constraints! Add unique constraints for columns not expected to have duplicated values. – jarlh Mar 08 '15 at 09:31
  • You may get idea from http://stackoverflow.com/a/18651899/2459296 – MD SHAHIDUL ISLAM Mar 08 '15 at 09:40
  • Find out what need to be unique in your form and make that element's db column unique. One more thing if you want to update the existing record in case of duplicate then have a proper condition in your php code. Hope this will work. :) – Dipen Adroja Mar 08 '15 at 09:41

1 Answers1

0

1.) ALTER TABLE tablename ADD UNIQUE (column name). 2.) Unset your REQUEST,POST OR GET variable after submit your form.

Navjot Singh
  • 514
  • 4
  • 14