Double entries in MySQL Database

Is there a php script to check if the user has entered a duplicate entry in mysql row? Or least show me how to start the script or direct me to a good guide. Let say the someone is adding a description that is the same to another description.
Who is Participating?
lexlythiusConnect With a Mentor Commented:
Easier done in MySQL itself:
SELECT t.*, COUNT(*) AS duplicate_count 
FROM YourTable t
GROUP BY YourFieldThatShouldHaveAnIndex
HAVING duplicate_count > 1

Open in new window

A very simple soluion can be obtained at the MySQL database side.  Just set the field to require a unique value -- then an error will be generated if a duplicate value is entered.  Since you are needing unique values, I would look at the field as a good candidate to index as well.
Jagadishwor DulalBraces MediaCommented:
Again if you want to check the value exist or not than you should use select query and check the value exist or not like:
$q="SELECT * FROM tblname where fieldname='$value';
echo "$value already found in database";
//run your insert query here

Open in new window

My solution helps you when you want to find out existing duplicates.

@jagadishdulal solution works best if you have a user input you want to validate prior to inserting it into DB.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.