在重定向到另一个页面之前显示弹出div html

i use redirect after insert syntax to prevent double insertion in php

here is my php code:

if (mysqli_num_rows($result_email) > 0)
{
    $emailerror = true; //display pop up working properly
}
else 
{
      //insert sql syntax 
      $emailerror = false;
      header('Location: index.php');
}

insert sql syntax works but when refresh the page the insertion is doubled that's why i add header location to prevent it. but i want to display pop-up register success after registration and redirect to another page

here is my short html code:

<?php
if ($emailerror == true)
{
    echo "<div class='popup_email_error'> </div>";
}
else if($emailerror == false)
{
     echo "<div class='popup_register'> </div>";
}
?> // this code is working properly without header location syntax but the problem is the insertion sql is always doubled

i want to pop up first before redirect to another page or vice versa how to prevent the double insertion without header location

i already tried javascript redirect works but the insertion of syntax is double

You could use flash package to send them to your view. It will be stored in your $_SESSION variable per one call including redirection.