skip to Main Content

i am using local server with PHP V7.3.12 and this code runs successful

if(mysqli_num_rows($query) >0 ) 
{
  echo "<script>alert('You are already registered');</script>";
 header("location:http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/packnowledgement.php");

}

but on the hosting server with PHP V7.3.28 is not running it run the alert message and stays on the current page.

please is there any difference in the PHP version?

2

Answers


  1. It can not work. You send out a header, but you cant do that when you’ve sent ANY output.

    In your case you have an echo which outputs text (in the form of a scripttag that makes an alert), so your header wont work.

    The reason this might’ve worked is that the previous version surpressed that error, but it has always been there. You’re now experiencing the proper behaviour, frustrating as that might be.

    Offtopic: If you stay on the same domain, you can remove the HTTP_HOST part from the header and simplify.

    Login or Signup to reply.
  2. You can also do this in javascript, Have a look at this

    if(mysqli_num_rows($query) >0 ) 
    {
      echo "<script>
              if(alert('You are already registered')){
              window.location.href = './packnowledgement.php';
              }
           </script>";
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search