每次刷新页面的upcount和downcount递增?

the upcount and downcount columns are incrementing on every page refresh and that shouldn't happen it should happen only on button click what should i do? here i have implemented upvote and downvote mechanism

//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();

}

Just after the update query, you should redirect to the same page, this will empty the posted data from the http header

header('location:'$_SERVER['PHP_SELF']);