edc Posted October 5, 2012 Share Posted October 5, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/269118-duplicate-inserts/ Share on other sites More sharing options...
trq Posted October 5, 2012 Share Posted October 5, 2012 Why on earth would you need to deploy that to three different locations in the first place? Quote Link to comment https://forums.phpfreaks.com/topic/269118-duplicate-inserts/#findComment-1382868 Share on other sites More sharing options...
edc Posted October 5, 2012 Author Share Posted October 5, 2012 I don't. I am trying to debug a different insert problem and boiled it down to this simple step. I know I am new here, but how does your question even help a little? I have done TONS of homework on this. Quote Link to comment https://forums.phpfreaks.com/topic/269118-duplicate-inserts/#findComment-1382869 Share on other sites More sharing options...
PFMaBiSmAd Posted October 5, 2012 Share Posted October 5, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/269118-duplicate-inserts/#findComment-1382876 Share on other sites More sharing options...
mdmartiny Posted October 5, 2012 Share Posted October 5, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/269118-duplicate-inserts/#findComment-1382878 Share on other sites More sharing options...
KevinM1 Posted October 5, 2012 Share Posted October 5, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/269118-duplicate-inserts/#findComment-1382892 Share on other sites More sharing options...
edc Posted October 5, 2012 Author Share Posted October 5, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/269118-duplicate-inserts/#findComment-1382903 Share on other sites More sharing options...
Christian F. Posted October 5, 2012 Share Posted October 5, 2012 Have you verified with the database directly that there are indeed duplicated data, or have you only checked with your own interface? Quote Link to comment https://forums.phpfreaks.com/topic/269118-duplicate-inserts/#findComment-1382936 Share on other sites More sharing options...
aangulo Posted October 29, 2012 Share Posted October 29, 2012 I think I am having the same problem...Transferred from one server to another, same code is now making duplicate inserts...Where you able to find a cause or shed some light on this? Quote Link to comment https://forums.phpfreaks.com/topic/269118-duplicate-inserts/#findComment-1388374 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.