473,396 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Duplicate records problem

Hi, I'm building a basic forum type thing but having a problem with getting records duplicated when people reply to a post.

This is the code I'm using to process the replies...[php]
$thread_id = $_POST["thread_id"];
$details = strip_tags($_POST["details"], "<b><i><u>");
$member_id = $_POST["member_id"];
mysql_query("INSERT INTO forumReplies (Details, MemberID, ThreadID) VALUES ('" . $details . "', '" . $member_id . "', '" . $thread_id . "')");
header('Location: details.php?id=' . $thread_id);[/php]It works, but the problem is that SOME (apparently at random), get repeated when the user hits submit, but some don't. I can't work out any reason for it. It seems that the code is being run twice on some occations.

I looked at the data in the database and it does indeed post two exact copies of the same post (with different record ID's).

I have recently updated to MySQL from an Access driven version. I also had exactly the same problem with Access (similar ASP code) but assumed that it was just crappy Access. It seems not.

Any help is really apreciated!
Mar 27 '08 #1
4 2277
ronverdonk
4,258 Expert 4TB
Welcome to The Scripts! BUT:

Please enclose your posted code in [code] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use [code] tags in future.

MODERATOR
Mar 27 '08 #2
ronverdonk
4,258 Expert 4TB
Can it be that someone hits the submit button twice or someone refreshes the page? That would be a cause and you will have to guard against that.

By the way: you can write that query easier this way (as long as it is between double quotes):[php]mysql_query("INSERT INTO forumReplies (Details, MemberID, ThreadID) VALUES ('$details', '$member_id', '$thread_id')");[/php]
Ronald
Mar 27 '08 #3
Sorry about not using CODE tag, I will make sure I do in the future.

Thanks for the code advice. Hitting the button twice was a thought I had too, but it happens when I try it too and I'm definatly only submitting once. I have some javascript that disables the submit button after submit. It could be submitting twice (which would make sence) without me realising it.

Can anyone suggest a better way to prevent a form being submitted more than once?
Mar 27 '08 #4
ronverdonk
4,258 Expert 4TB
As I said, a refresh of the page or a page-back and refresh could do the same.

Ronald
Mar 27 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: JStrummer | last post by:
I just put together a PHP mailing list sign-up page that posts to a mySQL DB. The PHP script prevents INSERTs when the email address is already located in the database. Problem: I need to import...
3
by: Nhmiller | last post by:
I searched here for an answer. I am entering records into a database, and it would save a lot of time if I could duplicate a record that is very similar to the new one I am about to enter, then...
2
by: stranger | last post by:
My database is set up so people can input parts orders. Sometimes they order the same parts on a monthly basis. I want to be able to duplicate past parts orders and have it pasted in with a new...
6
by: sara | last post by:
I have a procedure to automate bringing several Excel files into our Access tables, on a daily basis. The problem is that if the user has a problem, and tries to run the import again (maybe 3...
0
by: claus | last post by:
Hi, I am not a programmer but tries anyway to program a feature in a form where I am able to copy entries for the form and a subform. I have tried follow the guide here...
2
by: mivey4 | last post by:
Okay I have 2 tables: Table A - holds a list of new hardware serial numbers and their corresponding model (no constraints or indexes) Table B - holds a distinct list of current serial numbers...
2
by: nethravathy | last post by:
Hi, The following table namely elcbtripselect contains 5147 records.I want to know wether this table contains duplicate records or not. I tried with following query 1)SELECT...
4
by: Thomas Arthur Seidel | last post by:
Hello to all, I have a small or big problem with a customer data base, where during a change of system we might have created duplicate records. This should be easy to find, you might think, but,...
2
by: nomvula | last post by:
hi guys i need some help to duplicate records on my form datasheet: here's the example of my form results: ClientLookup DateCaptured ForecastDate Description ForecastQuantity Forecast Actual UJ...
1
by: xraive | last post by:
I have a problem with this. Currently I am trying Allen's code and i am not successful. Current Design Table1 (Main Form) TravelID (PK) ApprovedBY EntreredBy BudgetCode ExpenseCode
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.