I have a simple application which allows users to submit 'problems' and then comment on them. I am attempting to make a simple voting system so users can 'vote up' problems which in turn will push them higher up a list. I have some basic knowledge of PHP and everything so far is working, I just can't figure out how to get this to work.
I've followed a tutorial online and so far have this on my problem.php page...
if (isset($_GET['vote'], $_GET['id'])){
add_problem_vote($_GET['id]'], $_GET['vote']);
}
<a href="?vote=up&id=<?php echo $problemID; ?>">Vote</a>
And on my functions.php page...
function add_problem_vote($problemID, $vote){
$problemID = (int)$problemID;
$vote = ($vote === 'up') ? '+' : '-';
$sql = "UPDATE `problems` SET `votes` = `votes` {$vote} 1 WHERE `id` = {$problem_id}";
mysql_query($sql);
}
All my table fields are definitely named correctly. I know there are many things to consider like re-voting after the session has closed but as long as I have shown the idea it doesn't have to be perfect. At the minute when the link is clicked it redirects to a page but the votes don't change in the mysql table.
$sql = "UPDATE `problems` SET `votes` = `votes` ".$vote." 1 WHERE `id` = ".$problem_id;
mysql_query($sql) or die(mysql_error());
Check what error you are getting ?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With