开发者

Increase or Decrease field using upvote and downvote buttons

Novice to php / mysql: I have a table with 2 fields (id, rating). I want to create a form with 2 buttons (upvote, downvote) that essentially update the 'rating' f开发者_如何学Cield of the selected id (selected at random).

Here is what I have been trying to make:

<form method="post">
<input name="upvote" type="image" src="up.png"id="rateup" value="upvote" />
<input name="downvote" type="image" src="down.png"id="ratedown" value="downvote" />
</form>
<?php
mysql_connect("-","-","-")or die(mysql_error());
mysql_select_db("-")or die(mysql_error());
if(isset($_POST['rateup']))
{
    $sql("UPDATE utube SET rating = rating + 1 WHERE id = '$saved_row[id]'");
}
if(isset($_POST['ratedown']))
{
    $sql("UPDATE utube SET rating = rating - 1 WHERE id = '$saved_row[id]'");
}
?>

I am sure I am going disastrously wrong in places, I just can't find a suitable guide to doing something like this. All and any guidance is appreciated!


Check the mysql_query() function

$sql = mysql_query("UPDATE utube SET rating = rating + 1 WHERE id = '$saved_row[id]'");


Try this:

$sql = mysql_query("UPDATE utube SET rating = rating + 1 WHERE id = '{$saved_row[id]}'");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜