单击按钮提交时,数据库中的数据输入两次

Why when I click on the submit button for the first data it just entered in the database but it is not in the page view. after that click again once the data is entered in the page, but when I check the database, the data is two of the same. how about.

<?php
include 'xx.php';
?>
<!DOCTYPE html>
<html>
    <head> 
    </head>
    <body>

        <form method="post" >

       <center>
                    <div>
                        <tr>
                            <td>
                                <label><b>User</b></label>
                                <input type="user" placeholder="User" name="user" required>
                            </td>
                        </tr>
                    </div>
                    <div>
                        <tr>
                            <td>
                                <label><b>Position</b></label>
                                <input type="position" placeholder="Position" name="position" required>
                            </td>
                        </tr>
                    </div>
                    <div>
                        <tr>
                            <td>
                                <label><b>Serial Number</b></label>
                                <input type="serial" placeholder="Serial Number" name="serialnumber" required>
                            </td>
                        </tr>
                    </div>
                    <div>
                        <td>
                            <center>


                                  <input type="submit" name="send"  value="Submit"></input></center>

                            </center>
                        </td>
                    </div>
    </body>
</html>
<?php 
    if (isset($_POST['send'])) {
       
        $user=$_POST['user'];
        $position=$_POST['position'];
        $serialnumber=$_POST['serialnumber'];
        
        
        $xx="INSERT INTO xx (user,position,serialnumber)VALUES('$user','$position','$serialnumber')";
        $result=mysqli_query($dbconfig,$sql);
 echo "<script language='javascript'>window.location.href='xx.php'</script>";
}
?>

</div>

Try this. When you click the button it will disable the button, change the text and then submit the form.

That means the button will be disabled for anymore clicks.

<input 
    type="submit" 
    name="send" 
    value="Submit" 
    onclick="this.disabled=true;this.value='Submitting...';this.form.submit();"
>

Possible to add this code on top section and review my code.

  $i=1;
    if (isset($_POST['send'])) {

        $user=$_POST['user'];
        $position=$_POST['position'];
        $serialnumber=$_POST['serialnumber'];
        $department=$_POST['department'];
        if($i==1):
            $sql="INSERT INTO xx (user,position,serialnumber,department)VALUES('$user','$position','$serialnumber','$department')";
            $result=mysqli_query($dbconfig,$sql);
            $i++;
        endif;

        if(isset($result) && !empty($result)):
            $i=1;
            echo "<script language='javascript'>window.location.href='xx.php'</script>";

        endif;
    }