如何通过php函数调用刷新当前所在的页面?

如何通过php函数调用刷新当前所在的页面?,php,mysql,sql,Php,Mysql,Sql,用户点击follow/unfollow按钮后,会出现相同的按钮(因为页面未刷新,如果用户再次单击按钮,则会弹出错误,因为用户尝试访问重复字段)但是,我希望页面在单击任何按钮后刷新这是我为php和所用函数编写的代码: function unfollow($userid, $uploader_id){ if(isset($_POST['unfollow'])){ $con = mysqli_connect('localhost', 'root

用户点击follow/unfollow按钮后,会出现相同的按钮(因为页面未刷新,如果用户再次单击按钮,则会弹出错误,因为用户尝试访问重复字段)但是,我希望页面在单击任何按钮后刷新这是我为php和所用函数编写的代码:

            function unfollow($userid, $uploader_id){

        if(isset($_POST['unfollow'])){
        $con = mysqli_connect('localhost', 'root', '', 'db');
            $userid = sanitize($userid);
            $uploader_id = sanitize($uploader_id);
            //prepare statement
            $stmt = $con ->prepare("DELETE FROM follow
    WHERE u_id = ? AND uploader_id = ?");
            $stmt -> bind_param("ss",$userid, $uploader_id);
            if($result = $stmt->execute()){
                header("Refresh:0");
                echo "<h1 style='clear:left;font-size:15px; color:blue;'>UnFollowed</h1>";  
            }
        }
        }


function follow($userid, $uploader_id){

 if(isset($_POST['follow']))
{
if(logged_in()){

if($userid != $uploader_id){
    $con = mysqli_connect('localhost', 'root', '', 'db');
    $userid = sanitize($userid);
    $uploader_id = sanitize($uploader_id);
    //prepare statement
     $stmt = $con ->prepare("INSERT INTO follow (u_id, uploader_id) VALUES    (?, ?)");
     $stmt -> bind_param("ss",$userid, $uploader_id);
        if($result = $stmt->execute()){ 
        header("Refresh:1");
            echo "<h1 style='clear:left;font-size:15px; color:blue;'>Followed</h1>";    
        }

         else{
            echo "Failed to follow";    
        }
    }// users cant follow themselves


   }//if not logged in do this
   else{
      echo "<h1 style='clear:left;font-size:15px; color:red;'>You have to be logged in to follow</h1>"; 
       }
   }
}
函数unfollow($userid,$uploader\u id){
如果(isset($_POST['unfollow'])){
$con=mysqli_connect('localhost','root','db');
$userid=sanitize($userid);
$uploader\u id=消毒($uploader\u id);
//准备报表
$stmt=$con->prepare(“从follow中删除
其中,u_id=?和上传程序_id=?”;
$stmt->bind_参数(“ss”、$userid、$uploader_id);
如果($result=$stmt->execute()){
标题(“刷新:0”);
呼应“未跟随”;
}
}
}
函数follow($userid,$uploader\u id){
如果(isset($_POST['follow']))
{
如果(已登录()){
如果($userid!=$uploader\u id){
$con=mysqli_connect('localhost','root','db');
$userid=sanitize($userid);
$uploader\u id=消毒($uploader\u id);
//准备报表
$stmt=$con->prepare(“插入后续(u\u id、上传器id)值(?)”;
$stmt->bind_参数(“ss”、$userid、$uploader_id);
如果($result=$stmt->execute()){
标题(“刷新:1”);
回声“跟随”;
}
否则{
echo“跟踪失败”;
}
}//用户不能跟随自己
}//如果未登录,请执行此操作
否则{
echo“您必须登录才能跟随”;
}
}
}
我在php中以以下格式使用它:

    <?php

   //if the user is not logged in just display a button that send                  him/her to the login page if clicked 

    if(!logged_in()){
    ?>
     <form id="follow" style="clear:left;" action="">

     <button id="follow_btn" type="submit">Follow</button>

     </form>

   <?php 
    }

 //if the user is not following the uploader show the follow button

    else if(!is_following($session_user_id, $uploaderid)){

    ?>

   <form id="follow" method="POST" style="clear:left;" action="<?php                    follow($session_user_id, $uploaderid) ?>">

   <button id="follow_btn" type="submit" name="follow">Follow</button>

   </form>
   <?php 

  //else show the unfollow button
   }else{
    ?>
   <form id="follow" method="POST" style="clear:left;" action="<?php     unfollow($session_user_id, $uploaderid) ?>">
    <button id="follow_btn" type="submit" name="unfollow">UnFollow</button>
    </form>

    <?php
    }
    ?>

跟随

sanitize在这里做什么,它执行什么功能?sanitize是一个使用mysqli\u real\u escape\u字符串的函数,但是我已经改变了我的问题,因为我自己找到了解决方案。我非常感谢你的帮助。因为你使用了占位符值,这很好,你不需要“清理”任何东西。这导致了双重逃逸,这是一个巨大的问题。让司机替你做这项工作。