我想在PHP中做一個簡單的投票腳本並需要幫助。我遇到的問題是我創建了一個帶有兩個按鈕的窗體,喜歡和不喜歡,它們對應於if else語句。PHP if if語句來自兩個按鈕
如果類似按鈕被點擊做更新,否則點擊不喜歡按鈕做更新。
這裏是我到目前爲止的代碼,有更多的上面,但沒有必要我的問題:
while($row = $q2->fetch())
{
$up_vote= $row['up_votes']; /*Current Up Votes*/
$down_vote= $row['down_votes']; /* Current Down Votes*/
echo '<form method="post" action="">';
echo '<input type="button" id="up_vote" name="up_vote" value="Like" /> OR';
echo '<input type="button" id="down_vote" name="down_vote" value="Dislike" />';
echo '</form>';
echo round($row['rating'], 0);
echo '% of voters Liked this';
}
$up_votes = $up_vote +1;/*$up_vote referes to original # of up_votes, $up_votes adds 1 to the number of votes*/
$down_votes = $down_vote +1;/*$down_vote referes to original # of down_votes, $up_votes adds 1 to the number of votes*/
if ($something);/*upvote clicked*/
{
$vote_update = "UPDATE images
SET up_votes:up_votes
WHERE vote_item_id: vote_item_id";
$q3 = $conn-> prepare($vote_update);
$q3->execute(array(':up_votes'=>$up_votes, /*$up_vote referes to original # of up_votes, $up_votes adds 1 to the number of votes*/
':vote_item_id'=>$current_vote_item_id));
/* ALSO create INSERT INTO votes_done to track the user vote*/
$conn = null;
}
else ($something2);/*down vote clicked*/
{
$vote_update = "UPDATE images
SET down_votes:down_votes
WHERE vote_item_id: vote_item_id";
$q3 = $conn-> prepare($vote_update);
$q3->execute(array(':down_votes'=>$down_votes, /*$down_vote referes to original # of down_votes, $up_votes adds 1 to the number of votes*/
':vote_item_id'=>$current_vote_item_id));
/* ALSO create INSERT INTO votes_done to track the user vote*/
}
應該採取什麼if和else語句是什麼樣子?我不知道該怎麼做,不能有兩個提交,我應該有兩種不同的形式,每個按鈕一個?無論哪種方式,我怎麼能說,如果像點擊去如果和運行代碼,或者如果不喜歡被點擊去別的和運行代碼?
感謝
這是有道理的,謝謝。 – Owen