Ensuring a user Can't vote twice

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
arpowers
Forum Commoner
Posts: 76
Joined: Sun Oct 14, 2007 10:05 pm
Location: san diego, ca

Ensuring a user Can't vote twice

Post 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
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Ensuring a user Can't vote twice

Post 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.
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
arpowers
Forum Commoner
Posts: 76
Joined: Sun Oct 14, 2007 10:05 pm
Location: san diego, ca

Re: Ensuring a user Can't vote twice

Post 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)
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Ensuring a user Can't vote twice

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply