Why do duplicate rows get inserted?

It turns out to be a good thing that you made a copy, because now that’s our only copy. :stuck_out_tongue:

It occurs to me, Busboy, that we don’t yet know which table you’re getting duplicates in. I see that you’re inserting into a “matches” table from within a do-while loop. Any chance the matches table is the one you’re having problems with?

The table that I’m currently seeing duplicates in is the notifications table. This is where I store emails that will be emailed out using a cron job. I’m attaching a .pdf of my code, which will hopefully make things much easier to read. Rudy, you will likely recognize some of the advanced queries. :slight_smile:

http://oil-testimonials.com/examples/myCode.pdf

Hey, where did everyone go? All I hear is crickets.

:slight_smile:

I ran your code (though I had to fix several errors before it would run at all), but the notification query ran only once. From the code shown here, I can’t find any reason for the duplicate inserts. You’ll probably need to get the help of someone who you can allow access to your full application and database, so that person can reproduce and trace the issue.

So I’m assuming $longDate does not include the time? My guess is there are multiple http requests happening here.

Jeff, you ran my code and had to fix several errors? How did you do this since the code I supplied requires the use of a mySQL database with the same tables that I use?

Wolfe, at the very top of the code, $longDate is defined as $longDate = date(“Y-m-d H:i:s”); Maybe this is a multiple http request issue, because the duplicate rows are storing slightly different dates. What causes multiple http requests and how do I get rid of them?

Thanks!

Hi

How are you submitting the form? You don’t have any pesky JavaScript do you that could be causing the double submit?

Whats the setup on these testimonials? Should they be able to submit more than one?

I logged the SQL that would have been executed, rather than actually executing it.

Richard, there is no javascript used in this code.

Wolfe, users can submit as many testimonials as they want, they just need to be unique. Remember, the testimonies table is not having problems with duplicates, it just seems to be the notifications table.

Someone earlier mentioned that this problem might be caused by multiple http requests. So, my latest idea is to create a new column in the notifications table that would store a randomly generated 4 digit code. Then I could create a unique index that includes the uID, type, and generatedCode columns. I thought I was covered by using the date column, but since the duplicate inserts are sometimes several seconds apart, the unique constraint fails to do its job.

I know this is kind of a hack, but does anyone have a better idea?

Thanks!

Still looking for a little help on this, if possible.

Thanks!

You should have two tables from what I’m reading, 1 table for your testimonials, the other for email subscriptions, the emails subscription table should have a primary key of email, to prevent more than one email from entering the table, thus stopping duplicate emails from going out, no matter how many testimonials they write.

Yes, but what about the multiple http requests? What is causing this to happen?

Your not going to be able to stop a user from submitting a form multiple time, the data IS GOING to hit your script, its up to you to stop bad data from coming in to your db.

For each testimonial they want to START, create a unique ID for that session. This will be your primary key on the testimonial table. Create a new session each time they want to start a new testimonial.

I got it figured out now. Thanks for your help everyone!!