Jump to content

Recommended Posts

Hi Guys

 

This "simple" problem has me pulling my hair out. Source code attached.

 

I have the same Database and Table on 4 different machines. I have been trying to solve this for a few days.

 

When I run the attached source on my local boxes it works exactly as one would expect. That is inserts 1 record into the table.

 

When I run the attached source on my 2 different web hosts, it inserts 2 records into the table. I have tried this MANY times.

 

Does anyone even have a theory?

 

My only thoughts now are thought some lib is screwed up some where. I am about 99.9% sure it is NOT my php code BUT figuered this would be the best place to ask.simple.php

Link to comment
https://forums.phpfreaks.com/topic/269118-duplicate-inserts/
Share on other sites

Web pages can get requested two times for a handful of different reasons -

 

1) The browser requests it twice, either due to debugging plug-ins, the character encoding set in the browser that is different from the character encoding set in the page, even something to do with fetching the favicon then fetching a page again.

 

2) You have some javascript on the page that is requesting your page that causes it to be requested twice, such as submitting a form using javascript and also letting the browser submit the form.

 

3) You are including the code twice on the server or including/running it inside of a loop.

 

4) You have URL rewriting that causes the page to be requested for both the original request and also for the rewritten request. If I remember correctly this involves something about a trailing slash / or lack of on the url.

 

5) Your web server is behind a proxy server at your hosting company and is being sent two requests.

 

Since most of these things are out of your control, you normally detect and prevent duplicate data submission in your code on the server.

Link to comment
https://forums.phpfreaks.com/topic/269118-duplicate-inserts/#findComment-1382876
Share on other sites

Where is your source code? I do not see it.

 

Nevermind I found the attachment. If that is the code that you are using then it will allow for multiple entries in the database. In order to prevent that from happening you need to have an auto incremented field. That will give you an unique field that will allow not allow duplicated entries.

Link to comment
https://forums.phpfreaks.com/topic/269118-duplicate-inserts/#findComment-1382878
Share on other sites

Where is your source code? I do not see it.

 

Nevermind I found the attachment. If that is the code that you are using then it will allow for multiple entries in the database. In order to prevent that from happening you need to have an auto incremented field. That will give you an unique field that will allow not allow duplicated entries.

 

Auto increment has nothing to do with duplicated data. All it would do is the following on insert:

 

id          first_name            last_name            age
1          Peter                Griffin                35
2          Peter                Griffin                35

 

A unique or primary key will do what you suggest. That said, it doesn't address the actual problem, which is his code apparently executing twice.

Link to comment
https://forums.phpfreaks.com/topic/269118-duplicate-inserts/#findComment-1382892
Share on other sites

One piece of information to add. I turned on logging on the mysql side and in the logs I see the sql and I only see it once.

Could it be that some encoding character is making the MYsql engine do a double insert?

This is nuts.

 

Does anyone have a virtual server on GoDaddy.. maybe you can try it yourself.

Link to comment
https://forums.phpfreaks.com/topic/269118-duplicate-inserts/#findComment-1382903
Share on other sites

  • 4 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.