Im using a simple ajax script to allow users to vote against multiple posts on a page. However I dont want the same user to vote against the same post more than once, to try and avoid this I log the users, ID, Username and the ID of the post to which they have voted in a database.
Like so:
$updatevoters = "INSERT INTO voters VALUES('$userid', '$id', '$username')";
What I now need to do is before submitting the vote to the database is make sure that the user hasnt already done so.
How can I query the database, Im thinking of using COUNT
or something similar, to check if there are any matches?
Im not sure how to take all 3 variables $userid, $id and $username
and compare against the voters
table.
Essentially I'd like to be able to build an IF:
If ($count = 0) {
ADD THE VOTE TO TABLE
} else {
//DIE
}
Any help appreciate....