为什么用户表单提交消息未打印(在通过浏览器停止确认表单提交警报后)

Query to insert the values in database

$query = "select * from logintb WHERE username = '$username'";
$query_run = mysqli_query($con,$query);

if(mysqli_num_rows($query_run)>0){
    echo 'username already exists!!';                                                   
}else{
    $query="insert into logintb values('$fullname','$username','$gender','$address','$pnumber','$email','$encrypted_password')";    
    $query_run = mysqli_query($con,$query);

    if($query_run){                                 
        echo "Registered successfully!";
        echo("<script>location.href = 'signUp.php';</script>");

    }else{                                              
        echo '<script type="text/javascript"> alert("Error!") </script>';
    }
}

basically i was working on how to prevent the browser confirm form submission alert.Because it causes data to enter twice in database.so i redirect the page to itself.right now it solved my problem but couldn't print the message that user registered successfully because it reloads the page.any solution?

you need to place the insert and check into if (isset($_POST['submit-user'])) { } where submit-user is your button

if (isset($_POST['submit-user'])) {

    $query = "select * from logintb WHERE username = '$username'";
    $query_run = mysqli_query($con,$query);

    if (mysqli_num_rows($query_run) > 0) {

        echo 'username already exists!!';

    } else {

        $query="insert into logintb values('$fullname','$username','$gender','$address','$pnumber','$email','$encrypted_password')";    
        $query_run = mysqli_query($con,$query);

        if ($query_run) {

            echo "Registered successfully!";

        } else {                                          

            echo '<script type="text/javascript"> alert("Error!") </script>';

        }

    }

}

// HTML <form method="post"></form> goes here...

There are two solutions:-

echo "<script>alert('Registered successfully!');</script>";

The above will show the successful message as an alert and after clicking will reload the page . Or otherwise , go for JavaScript / JQuery registration process to make it faster and without reload .