How to prevent double form submit on the php or mysql level?
I know I can do disable the button via js, but the user can easily alter that in his browser.
So, I am looking for an easy solution how to do that.
I have tried this SESSION trick
https://stackoverflow.com/questions/20766744/php-double-form-submit-prevent however, I can still click fast and it will save many things in the db.
Also, if I do the
does a row with the same user_id, item_id and comment_id in the table reviews exist then stop condition -> this doesn't work either, when I click very fast on the button.
Does mysql have some function to refuse saving more than one row with the same info?
If something like that exists that would be great.
user_id, item_id, comment_id can be save only once or perhaps using some time prevention to save multiple things.
Design your data such that multiple submissions will not result in multiple entries.
Here are 2 ways to accomplish that, I prefer the second.
[Unique columns]1 and the
@ sign to suppress errors in php. <- this results in the most recent submission being inserted
Or better yet you can do a call to the DB and see if the information already exists and if so, dont make the
insert call. <- this results in the first submission being
inserted. Conditional logic can segue to an
update call if that is appropriate.