PHP空白屏幕弹出消息后的白色屏幕

i got a question in php, I want my code to display a popup message if the username or ID already exist in the database, I have the code running below, the problem is after clicking the popup box or clicking ok, a blank screen/white screen appear.

if ($check2 != 0) {
    echo"<script>alert('Sorry, the DAS ID is already in use.');</script>";
    die;
}

I tried the header function so the page will return to the same page where the popup error appeared, but when I do so, the popup error did not appear. Help please, I'm new in php.

if ($check2 != 0) {
    echo"<script>alert('Sorry, the DAS ID is already in use.');</script>";
    header("Location: register.php");
    die;
}

The "Location: " header immediately redirects the website to the specified URL. This means that your users are not likely going to be able read what the popup said at all if you use this header.

If you don't use a redirecting header, users will obviously see a blank page, since the page only contains the alert() script (assuming you hadn't echoed other stuff earlier) and as others have pointed out, die or exit immediately stops execution of the script wherever it's called.

Consider using the following instead:

if ($check2 != 0) {
    header("Refresh: 0; url=register.php");
    echo"<script>alert('Sorry, the DAS ID is already in use.');</script>";
    die;
}

No output before sending headers!

if ( $check2 != 0 ) 
{
    echo '<script>';
    echo 'alert("Sorry, the DAS ID is already in use.");';
    echo 'window.location.href = "register.php";';
    echo '</script>';

    die();
}

The first code the page is white by the "die" instruction.

if ($check2 != 0) {
echo"<script>alert('Sorry, the DAS ID is already in use.');</script>";
//die;

}

The second code you shoud to activate PHP error if you have an error on the new page (register.php)

die;

causes the white screen. Which tells the script to stop and send no more output to the client.

Depending on your form evaluation structure try somethind like:

if ($check2 != 0) {
    echo"<script>alert('Sorry, the DAS ID is already in use.');</script>";
    echo "<form><input type='text' name='...' >Put in here your input form again!</form>";
}else{
 echo "You did it!";
}