Alert Box before PHP action = "newpage.php" gets executed

Issue

I am new to php . and i am trying to pop up an alert box before the page action = "newpage.php" gets executed using the header function , but it isn’t working and every time without the alert box being popped up, i get redirected to the next page on successful form submissions.

what should i do to pop an alert box on successful submission of data in my database before going to the next page

here’s my code snippet that i have used to do so—->

if($conn->query($insertQuery)){
   if($_POST) {
         echo '<script>  alert("Registered");   </script>';
   }
   else{
         echo '<script>  alert("Not");   </script>';
   }
   header("location:login.php");

Solution

if($conn->query($insertQuery)){
   if($_POST) {
         echo '<script>  alert("Registered");   </script>';
   }
   else{
         echo '<script>  alert("Not");   </script>';
   }
echo '<script> window.location.href = "login.php";   </script>';

Try This

Answered By – Uttam Nath

Answer Checked By – David Goodson (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.