$con = mysqli_connect("localhost","root","","thesisdb");
if($upvote != "") {
/*im trying to do here , each of my image has vote/downvote button. but every image is increasing by one even you only vote for the selected image*/
$vote_upvote = "update product set vote=vote+1 WHERE ID = '".$upvote."' ";
$run_upvote = mysqli_query($con, $vote_upvote);
if($run_upvote){
echo "<h2 align='center'>You Upvoted It!</h2>";
}
}
/*same with downvote, all image increasing by one even you only click for one.*/
if($downvote != "") {
$vote_downvote = "update product set notvote= notvote+1 WHERE ID = '".$downvote."'";
$run_downvote = mysqli_query($con, $vote_downvote);
if($run_downvote){
echo "<h2 align='center'>You downvoted It!</h2>";
}
}
/ 我的显示图像更具体 /
$result = mysql_query("SELECT * FROM product");
echo "<table border='0'>
<tr>
<th>Product Name</th>
<th>Product Price</th>
<th>Product Type</th>
<th>Image</th>
</tr>";
$sw = 0;
while($row = mysql_fetch_array($result))
{
if($sw == 0)
{
$mycolor = "#fff";
$sw = 1;
}
else
{
$mycolor = "#fff";
$sw = 0;
}
echo "<tr bgcolor='".$mycolor."'>";
echo "<td>" . $row['ProductName'] . "</td>";
echo "<td>" . $row['ProductPrice'] . "</td>";
echo "<td>" . $row['ProductType'] . "</td>";
?>
/ *我在这里有一个两个按钮,它是upvote / downvote * /
<td><a name="upvote" href="customerview.php?upvote=<?=$row['ID']?>"><input type="submit" name="upvote" value="Upvote"/> </a> </td>
<td><a href="customerview.php?downvote=<?=$row['ID']?>"><input type="submit" name="downvote" value="Downvote"/> </a> </td>
<?php
echo "</tr>";
}
echo "</table>";
?>
答案 0 :(得分:0)
if($upvote != "") { //i dont know where you get this value from
将此行更改为
if(isset($_GET['upvote'])&&$_GET['upvote']!=""){
$upvote=$_GET['upvote'];
//your code to update upvote
}
if(isset($_GET['downvote'])&&$_GET['downvote']!=""){
$downvote=$_GET['downvote];
//here is your code to update downvote
}