-1

I have created a database which, amongst other things, holds data for votes cast for a place. I have managed to get it working to the point where the votes get counted and display correctly.

I want to introduce a cookie to make it harder for people to keep pressing vote. This is the code I have got thus far (sorry if it is horribly wrong am new to this). Basically I want it to check if the form has been sent and if a cookie does not exist, if so add a vote (otherwise do nothing - I'm still looking in to code to disable the form button in my software)

The page displays correctly but I get the "cannot display header information" message when clicking on the button and when I refresh, the vote has still been counted.

if (isset($_POST['votes']) && !isset($_COOKIE["placex"])) {
$query = mysql_query("UPDATE Places SET Votes = Votes +1 WHERE Places.Place='PlaceX'");
setcookie("placex");
}

// Default query
$sql = "SELECT * FROM Places WHERE Place='PlaceX'";

//execute the SQL query and return records
$result = mysql_query($sql);
?>

Thanks for any ideas!

cbladon
  • 1
  • 2
  • If you can or have time you will want to have users log in to vote so you can make sure only one vote per person – chrislondon Jul 04 '13 at 14:45
  • hi, I want to make it as easy as possible for people to just click to like something. I want to encourage votes but it looks silly to let people hammer away at it. – cbladon Jul 04 '13 at 14:48
  • If someone has disabled cookies on their browser they'll still be able to hammer away at it. – chrislondon Jul 04 '13 at 14:49

1 Answers1

0

This is a common problem - there must be no text output before using setcookie(). The error message should mention where the first output occured.

Ses http://www.geeklog.net/faqman/index.php?op=view&t=38 for more details

Thomas L.
  • 104
  • 8