I am trying to make a script for rating tutorials. I have it mostly worked out, but for some reason the script will not insert the data nor throw an error. Here is the script code:If shows the success message, but doesn't submit the vote. I am lost as to why it is doing this. I appreciate any help.PHP Code:<?php
$id = $_GET['id'];
// If vote sent
if ($_POST['vote']) {
$star = $_POST['star'];
// If voted before
if (isset($_COOKIE['voted']) && $_COOKIE['voted'] == ''.$id.'') { echo '<meta http-equiv="refresh" content="2;URL=tutorials.php" /> <span style="color: #FF0000">You have already voted!</span>'; }
// If have not voted
else {
@setcookie('voted', ''.$id.'', time() + ((60*60*60) * 72));
$get = mysql_query("SELECT star1, star2, star3, star4, star5, total FROM `ratings` WHERE id = '$id'") or die ("Error Getting Votes! \n<br />\n" .mysql_error());
$v = mysql_fetch_array($get);
// Update votes
if ($star == 1) { $update = mysql_query("UPDATE `ratings` SET star1 = star1+1, total = total+1 WHERE id = '$id'") or die ("Error Updating Votes! \n<br />\n" .mysql_error());
echo '
<meta http-equiv="refresh" content="2;URL=tutorials.php" />
Your vote has been submitted!';
}
elseif ($star == 2) { $update = mysql_query("UPDATE `ratings` SET star2 = star2+1, total = total+1 WHERE id = '$id'") or die ("Error Updating Votes! \n<br />\n" .mysql_error());
echo '
<meta http-equiv="refresh" content="2;URL=tutorials.php" />
Your vote has been submitted!';
}
elseif ($star == 3) { $update = mysql_query("UPDATE `ratings` SET star3 = star3+1, total = total+1 WHERE id = '$id'") or die ("Error Updating Votes! \n<br />\n" .mysql_error());
echo '
<meta http-equiv="refresh" content="2;URL=tutorials.php" />
Your vote has been submitted!';
}
elseif ($star == 4) { $update = mysql_query("UPDATE `ratings` SET star4 = star4+1, total = total+1 WHERE id = '$id'") or die ("Error Updating Votes! \n<br />\n" .mysql_error());
echo '
<meta http-equiv="refresh" content="2;URL=tutorials.php" />
Your vote has been submitted!';
}
elseif ($star == 5) { $update = mysql_query("UPDATE `ratings` SET star5 = star5+1, total = total+1 WHERE id = '$id'") or die ("Error Updating Votes! \n<br />\n" .mysql_error());
echo '
<meta http-equiv="refresh" content="2;URL=tutorials.php" />
Your vote has been submitted!';
}
else {
echo 'Please select a rating.';
}
}
}
// If vote not sent
if (!$_POST['vote']) { ?>
<!-- Vote Form -->
<form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<table width="200">
<tr>
<td><input type="radio" name="star" value="1" /></td>
<td>1 Star</td>
</tr>
<tr>
<td><input type="radio" name="star" value="2" /></td>
<td>2 Stars</td>
</tr>
<tr>
<td><input type="radio" name="star" value="3" /></td>
<td>3 Stars</td>
</tr>
<tr>
<td><input type="radio" name="star" value="4" /></td>
<td>4 Stars</td>
</tr>
<tr>
<td><input type="radio" name="star" value="5" /></td>
<td>5 Stars</td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="vote" value="Vote" /></td>
</tr>
</table>
</form>
<!-- /Vote Form -->
<?
}
?>



Reply With Quote





Bookmarks