Checking if some one has already voted

leo the lion

New Member
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: \[code\]$updatevoters = "INSERT INTO voters VALUES('$userid', '$id', '$username')";\[/code\]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 \[code\]COUNT\[/code\] or something similar, to check if there are any matches?Im not sure how to take all 3 variables \[code\]$userid, $id and $username\[/code\] and compare against the \[code\]voters\[/code\] table.Essentially I'd like to be able to build an IF:\[code\]If ($count = 0) { ADD THE VOTE TO TABLE} else { //DIE}\[/code\]Any help appreciate....
 
Back
Top