tags:

views:

177

answers:

5

I am inserting a value in to the table using php-mysql its getting inserted correctly.The insertion file in php is called through the ajax request. My problem is in some of the firefox version the request is triggered twice at some times and the records are inserted 6times with same datas in the table..How to prevent such situation without using unique concept...

A: 

MySQL offers a REPLACE command which is similar to INSERT but silently ignores duplicates. Documentation here.

Asaph
A: 

Using jQuery might help you (if you're not already). You can ensure that your code isn't executed too early with jquery's built in $(document).ready() event.

Also look at what is triggering the ajax call, if it is being done more times than you expected. You could also do some server-side checking to make sure that a query was not already submitted.

jjclarkson
+1  A: 

It sounds like the SQL does what it is told to. It's up to you to not execute the query with the same data over and over.

As you stated "in some of the firefox version the request is triggered twice", the problem is most likely in your client code, post that code for us to be able to help you.

(This should have been a comment but I'm too low on rep pts.)

chelmertz
A: 

Because you don't want to go with a UNIQUE index...

...I realized similiar problems by simply querying the table before the insert to look if the record already exists. I also implemented a time limit for the look up.

So this is what I do:

  1. I check the data if it's valid for insert in the table.
  2. I use this exact data for a select on the table, limited to all entries in the last 5 minutes.
  3. If the select returns no result, I insert the data in the table, otherwise I ignore it as "dublicate entry".
capfu
A: 

maybe using un duplicatable indexes in mySql db and for the browser you can use javascript to disable the submit button onclick so you will get only one click on it


top ten books

╗╔═╦══╦══╦═╔

http://10book.tk

╝╩═╩╩═╩╩═╝╩╚‏

abdo