473,397 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

How to prevent inserting duplicate database records?

47
how i want to check if there is duplicate entry in my database?? i insert new record which is the same record that i had inserted before,it successfull insert into the database..i don't want that.. what i want is the error must appear when i try to save the same previously record.. can you all help me please... newbie in php..
Jul 26 '08 #1
4 2667
ak1dnar
1,584 Expert 1GB
One solution is for this (may be not the best) is, there you can create a UNIQUE column in your table and when there is a duplicate entry you can trap the error.
Jul 26 '08 #2
azura
47
oh that means i have to make one of my data are in unique??
Jul 26 '08 #3
Atli
5,058 Expert 4TB
Hi.

I've changed the title of this thread to better describe it's content.
Please try to give your threads meaningful titles. Bad titles reduce the chance your question will be noticed by those who may be able to help!

Check out the Posting Guidelines for tips on how to make good thread titles.

Thanks.
Jul 26 '08 #4
Atli
5,058 Expert 4TB
Using a UNIQUE key is probably the best way to handle this.
That way, the Database server itself will prevent duplicate rows from being created, so your PHP application won't have to.
Although, you will have to make sure your code can detect and handle the error.

If you already have your table, you could add the UNIQUE key by using the ALTER TABLE syntax.
Like (assuming MySQL, but would probably work for others to)
Expand|Select|Wrap|Line Numbers
  1. ALTER TABLE tblName ADD UNIQUE (theColumn);
  2. /* Or if you need multiple columns */
  3. ALTER TABLE tblName ADD UNIQUE (col1, col2, /*...*/, colN);
  4.  
And as always, remember to test this before using it on any data you can't afford to lose.
Jul 26 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: entoone | last post by:
I have an html form, that has fields and when the submit button is pressed, the information is transferred to a php file. Which then inserts the data into my sql database. How can I go about...
4
by: keithb | last post by:
A page uses query string values to add a record to a database. The record should be added only once; however, if a user activates the url additional times, multiple records are added. Is there some...
11
by: ariel81 | last post by:
i have created a function to input data from four textboxes into a table. how do i prevent duplicate records of the same mth/Yr into the table? editing of the data in the table with reference to the...
7
by: ebindia0041 | last post by:
This is like the bug from hell. It is kind of hard to explain, so please bear with me. Background Info: SQL Server 7.0, Asp.net 1.1 with c# I'm inserting simple records into a table. But one...
3
by: veerapureddy | last post by:
Hai everybody, i like to insert some records into database from html form by entering data.my problem is how can i check , whether a record is available in database about a particular...
0
by: jehrich | last post by:
Hi Everyone, I am a bit of a hobby programmer (read newbie), and I have been searching for a solution to a SQL problem for a recent pet project. I discovered that there are a number of brilliant...
6
by: ashes | last post by:
Hi, I am creating an ecommerce website using Microsoft Visual Studio, VB.Net and MS Access 2003. I am new to VB.Net When someone wants to register on the website, they fill out a form and the...
2
by: AlexanderDeLarge | last post by:
Hi! I got a problem that's driving me crazy and I'm desperately in need of help. I'll explain my scenario: I'm doing a database driven site for a band, I got these tables for their discography...
2
by: hakkatil | last post by:
Hi to all, I have a page that inserts excel sheet to access database. I am using asp. What I want to do is to check the inserting record if it is in the database. Basicly checking the dublicate...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.