How to control / restrict users from commenting

1

I have my end-of-course project (in Web Application Development), in which I allow to value and comment to registered users different small commerce stores.

The thing is that how do I check that a user has commented or not to a trade? What I do not want is that a user can comment 10 times in the same trade, only 1 time for each one.

I need a bit of guidance, you do not need to code me or anything if you want, it's to know where to shoot since I'm a little lost.

    
asked by Anna 30.03.2016 в 11:42
source

1 answer

0

Assuming you have the comments in a mysql table that has the id of the trade and the id of the user, the simplest approach I can think of is to modify that table and add a unique type index between the trade id and the user id. This to guarantee from the model that there can not be more than one comment per user / trade.

Then, if an error occurs when trying to enter a new comment, you must trap / handle it to identify that it is said error and display a friendly message, such as "You already commented this trade"

Finally for the client side, when generating the page, verify if the user already has comments in said trade, the ideal would be that the box and button to send the comment are invisible.

    
answered by 30.03.2016 / 12:03
source