Page 1 of 1

Ensuring a user Can't vote twice

Posted: Tue Jan 15, 2008 1:03 pm
by arpowers
Hey quick question...

so we're putting together a discussion board that has a 'poll-type' capability.

Basically, if the users are already authenticated, what is the easiest way of making sure they can't vote twice on a poll???

Thanks as always,
Andrew

Re: Ensuring a user Can't vote twice

Posted: Tue Jan 15, 2008 1:09 pm
by VladSun
create a DB table:
user_id: poll_id

on voting - create the appropriate record.
So, if a record exists then user has already voted.

Re: Ensuring a user Can't vote twice

Posted: Tue Jan 15, 2008 1:20 pm
by arpowers
Thanks!
I guess my question really is... how do I check the table to make sure that the user hasn't voted?

Do I have to run two queries or can I do it all in one... (sorry if this is turning into a DB question)

Re: Ensuring a user Can't vote twice

Posted: Tue Jan 15, 2008 5:00 pm
by pickle
Which 2 actions do you want to do with 1 query? I wouldn't advise trying to authenticate and check the vote for a user in 1 query.

In 2 queries it's pretty straightforward. 1 query to authenticate the user, 1 query to see if that user id has already provided an answer for the poll.