Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP/MySQL problem-double record entry 1

Status
Not open for further replies.

mama1

Programmer
Jul 12, 2002
3
GB
I am running a PHP website retreiving information from MySQL database. MySQL record creation on certain fields is open to the end-user. I keep on getting double entry on those fields and therefore my PHP retreival on drop down lists contains those double entries. I am trying to eliminate this problem.
Please bear in mind that I am relatively new to PHP and MySQL. I dealt with JAVA and Microsoft's SQL before but PHP and MySQL is slightly different game to me.

Any help would be appreciated.

Thank you!
 
What is the source of your double-entry?

If you have a page where the user can enter data then hit submit to send to the server, the user's hitting submit twice will send the data twice, causing double entries.

If this is the source of your problem, remove the submit button and replace it with a regular button. Set the "onclick" event for the button to a javascript snippet which will check a variable to see whether the page as been submitted, then have javascript submit the page only if that has never been done before.


To keep the existing double entries from appearing in your retrievals, use "SELECT DISTINCT" instead of "SELECT" until you can get the database cleaned up.
 
Or you can do this with basic javascript:

<form method=&quot;post&quot; action=&quot;page.php&quot; onSubmit='submit.disabled = true;'>
<input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Add Message&quot;> If I have helped you just click the first link below to let me know :)
 
sleipnir214,

That avoids one thing, but doesn't avoid the refresh.

If you don't want duplicates, why not create an unique constraint in the database. That way you prevent dups.

Just another thing. I HATE that signatures of saying to ckick on the Stars. Helping others should be a pleasure and not a competition. Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
Anakin--What refresh?

Rick

P.S. Is this better? It's a pleasure to know that I've helped you. If I have,
please click the link below to let me know. :)
 
Anikin, neither you nor I know the source of his duplications. For all either of us know, it's because he's accidentally calling one of his functions twice.

We also don't know his schema and whether within it duplications are sometimes allowed.

I proposed one cause, and a solution. You posited another cause and provided another solution. C'est la vie.



<SARCASM type=facetious>
And it just breaks my poor widdle heart that you don't like my signature line, or approve of my motives.
</SARCASM>

C'mon. Out of the last 200 threads, comprising > 660 replies, only 32 stars have been awarded. If stars were my only motivation, I'd have moved on a long time ago.

And never forget the voting system serves another purpose: It allows users of the system to find a previously-posed solution to a similar question that someone else found useful. I think our &quot;successful assistance percentage&quot; is much better than 16%, don't you?

Besides, isn't an attaboy nice regarless of your reasons for doing something?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top