bluetoother Posted November 8, 2007 Share Posted November 8, 2007 i have a web page to receive users posts in my web site ,,it contain an editor , when user submit he submit to the same page,when the page check if there is a submitted data it insert the data in mysql database.sometimes when the page get submitted data it insert the data in the database 2 or 3 times , i mean same 3 identical records but with different record id which is the primary key and it is different because it is auto increment attribute .i tried to solve this by writing a cookie that remain for 2 minutes on the client's side when the insert sql command get executed , so if the user tried to insert records in shorter time , (IF) statement will prevent this and tell the user that he can insert after 3 mins ,but this didnt work.i cannot find an explanation to what is happening in that page when data is submitted to it.and why sql insert command got repeated more than one time .maybe it is SQL issue and this thread should be posted there .iam on php4 hosting server Link to comment Share on other sites More sharing options...
justsomeguy Posted November 8, 2007 Share Posted November 8, 2007 If the code is correct and it is only inserting one row then they are probably refreshing the page which will submit the same data and insert another row. You can get around that by saving the data that was last inserted into the session. When you do the insert check to see if the data to be inserted is the same as the data in the session and if so skip the insert. Link to comment Share on other sites More sharing options...
MrAdam Posted November 10, 2007 Share Posted November 10, 2007 do you use any loops in your code at all? Link to comment Share on other sites More sharing options...
bluetoother Posted November 11, 2007 Author Share Posted November 11, 2007 when user submit or refresh after submitting a cookie will be written to prevent inserting with in 3 mins,i dont user any loop in the code ,some times the page work normally,some times 2 rows got inserted some times 3 . Link to comment Share on other sites More sharing options...
justsomeguy Posted November 12, 2007 Share Posted November 12, 2007 It sounds like the cookies aren't working very well. If the code is correct and isn't inserting more then one row by itself then people are refreshing the page and the cookie isn't stopping it. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.