每个页面刷新时,upcount和downcount列都会递增 这应该不会发生它应该只发生在按钮点击我该怎么办? 在这里,我实施了upvote和downvote机制
// upvote and downvote
<?php
if(isset($_POST['up']))
{
$string= $_POST['up'];
$d= substr($string,0,2);
$t = ltrim($d, '0');
$id1=$id;
$conn1=new mysqli('localhost','root','','forum') or die(mysql_error());
$stmt1= $conn1->prepare("UPDATE messages SET upcount = (upcount+1) WHERE mid ='".$t."' ");
$stmt1->execute();
$stmt1->close();
}
if(isset($_POST['down']))
{
$string1= $_POST['down'];
$d1= substr($string1,0,2);
$t1 = ltrim($d1, '0');
echo $t1;
$conn1=new mysqli('localhost','root','','forum') or die(mysql_error());
$queryd=mysqli_query($conn1,"SELECT upcount FROM messages where messages.mid='".$t1."'");
$row=mysqli_fetch_assoc($queryd);
$up=$row['upcount'];
if($up>0)
$id1=$id;
$conn1=new mysqli('localhost','root','','forum') or die(mysql_error());
if($up>0)
{
$stmt2= $conn1->prepare("UPDATE messages SET downcount = (downcount+1) WHERE mid ='".$t1."'");
}
$stmt2->execute();
$stmt2->close();
$conn1->close();
}
答案 0 :(得分:0)
在更新查询之后,您应该重定向到同一页面,这将清空http标头中发布的数据
Rack::Lock#call