0

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.

For example user_id, item_id, comment_id can be save only once or perhaps using some time prevention to save multiple things.

Greggore
  • 11
  • 2
  • 2
    Well, you could set a UNIQUE INDEX on those three fields... but that is pretty brute force and inflexible. Depends on your structure and desired needs. – IncredibleHat Dec 27 '17 at 16:54
  • before you can save any data into the database , first check your database table to see if one of the submitted data like username already exists in the database table. if so flag the user, if not validate the form and save your information. –  Dec 27 '17 at 17:11
  • Ok, if I have a table `reviews` and fields `id, user_id, item_id, comment_id` and only one combination of each of these three (user_id, item_id, comment_id) is possible to save how to do that? – Greggore Dec 27 '17 at 17:13
  • @dean if you click too fast on the submit button this thing won't work. For some reason, the php allows parallel execution of mysql queries. and the if conditions in php won't work, because, the mysql process is not finished yet while others are being triggered. – Greggore Dec 27 '17 at 17:15
  • @Greggore, is user_id an int or a word? if its a word and attained from the submitted form like a username, you can query a database table and check if the user-id in already registered. if yes flag the user and if no register your data. - or provide a sample code and we will sort it out for you –  Dec 27 '17 at 17:19

1 Answers1

1

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.

NappingRabbit
  • 1,888
  • 1
  • 13
  • 18