I have a voting system which allows for users to upvote and downvote on items. I am looking to improve the system because users can vote multiple times. Below you can see my code.
<h4> Votes </h4>
<table>
<tr>
<th>Up-Votes</th>
<th>Down-Votes</th>
<tr/>
<tr>
<?php
mysql_connect("localhost", "root", "PASS") or die(mysql_error());
mysql_select_db("DBNAME") or die(mysql_error());
if ( isset( $_POST['Upvote'] ) )
{
mysql_query ("UPDATE reports SET up = up + 1 WHERE reportID = $id");
} else if (isset( $_POST['Downvote'] ))
{
mysql_query ("UPDATE reports SET down = down + 1 WHERE reportID = $id");
}
$data = mysql_query("SELECT * FROM reports WHERE reportID = $id") or die(mysql_error());
while($ratings = mysql_fetch_array( $data ))
{
Echo "<td>" .$ratings['up']."</td>";
Echo "<td>" .$ratings['down']."</td>";
}
?>
</tr>
</table>
<br/>
<form method='POST'>
<input type='submit' value='up' name='Upvote' class="myButton">
<input type='submit' value='down' name='Downvote' class="myButton">
</form>
Does anybody have any suggestions which could prevent duplicate votes?
There are potentially thousands of items on my system, I am unsure as to how I can make a user be exempt from voting on particular reports
Cheers