0

I made a like-unlike feature in my iOS-PHP Application.

(Of course userId and session is in the get parameter also)

Calling like.php?id=10 does two things

  • checks if the content 10 is liked already,
  • if not then adds a row to the database’s table

Calling unlike.php?id=10 removes the like the user has made.

—————

The problem is, that sometimes if the user likes-unlikes the given content too fast, my table will receive 2 rows of the given like.

————

I assume it is because two requests to the like.php file happens exactly at the same moment..

What could I do to prevent multiple rows from same user?

2 Answers 2

1

Use UNIQUE index in your database's table for user's id and content's id. The database will not insert a same user with same content in the like table.

Sign up to request clarification or add additional context in comments.

Comments

0

For me, 2 things: 1. Disable option for clicking button until request is finished (thanks to simple JS) 2. Lock the table for actions but keep it visible for reading for time of performing query.

you can even use both options so you will avoid having it clicked at the same time by 2 different users.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.