simple mysql vote script
Posted: Sun Mar 28, 2004 3:45 pm
Here's the code:
Not sure what i'm doing wrong, but the votetotal and totalvotes fields won't move from 0 in my database.
FYI, votetotal is the accumulated total of all votes. totalvotes is the total number of votes.
thanks
Code: Select all
<?php
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die("Unable to select database");
$query = "SELECT * FROM video WHERE id='$id'";
$result = mysql_query($query);
while ($r = mysql_fetch_array($result)) {
$vote = $_GET['vote'];
$votetotal = $r["votetotal"];
$totalvotes = $r["totalvotes"];
$insvotetotal = $votetotal + $vote;
$instotalvotes = $totalvotes + 1;
mysql_query("UPDATE video SET (votetotal='$insvotetotal', totalvotes='$instotalvotes') WHERE id='$id'");
mysql_close();
echo "Thank you for your vote! Current vote: $votetotal/$totalvotes <B>";
}
?>FYI, votetotal is the accumulated total of all votes. totalvotes is the total number of votes.
thanks