title: Javascript Alert Window Redirects to Another Webpage
body: <pre><code>    &lt;?php
  
  session_start();
  
  include_once "connect.php";
  
  $fullName = $_POST['fullname'];
  $userName = $_POST['username'];
  $emailAdd = $_POST['email'];
  $passWord = $_POST['password'];
  $query =  mysql_query("SELECT * FROM users where USERNAME = '$username' ");
  $result = mysql_fetch_array($query);
  
    if($fullName == "")
    {
  
  ?&gt;
      &lt;script&gt;
        alert("Full Name is required!");
        window.location.href = "registeruser.php";
      &lt;/script&gt;
  &lt;?php
    }
  
      else
      {
        if ($userName == "")
        {
  ?&gt;
          &lt;script&gt;
            alert("Invalid username!");
            window.location.href = "registeruser.php";
          &lt;/script&gt;
   &lt;?php     
        }
  
          else
          {
            if($userName == $result['USERNAME'])
            {
  ?&gt;
              &lt;script&gt;
                alert("Username already exists!");
                window.location.href = "registeruser.php";
              &lt;/script&gt;
  &lt;?php
            }
  
              else
              {
                if ($emailAdd == $result['EMAIL']) 
                {
  ?&gt;
                  &lt;script&gt;
                    alert("Email address is required!");
                    window.location.href = "registeruser.php";
                  &lt;/script&gt;
  &lt;?php
                }
  
                  else
                  {
                    if ($passWord == "")
                    {
  ?&gt;
                      &lt;script&gt;
                        alert("Username is required!");
                        window.location.href = "registeruser.php";
                      &lt;/script&gt;
   &lt;?php     
                    }
  
                      else
                      {
                        if($_POST['password']==$_POST['confirmpass'])
                        {
                          mysql_query("INSERT INTO users (FULLNAME, USERNAME, EMAIL, PASSWORD) 
                          VALUES ('$fullName', '$userName', '$emailAdd', '$passWord')" );
                          mysql_close();
  ?&gt;    
                          &lt;script&gt;
                            alert("Registered Successfully!");
                            window.location.href = "index.php";
                          &lt;/script&gt;
  &lt;?php
                        }
  
                          else
                          {
  ?&gt;
                            &lt;script&gt;
                              alert("Password and Confirm Password do not match");
                              window.location.href = "registeruser.php";
                            &lt;/script&gt;
  &lt;?php
                          }
                      }
                  }
              }
          }
      }   
  
  ?&gt;
  </code></pre>
  
  <p>It works fine. But the problem is: <strong>the alert window shows to another web page and NOT within the webpage</strong> It is okay but it looks awful to direct the user to another web page without having contents there. If you could help me please on how to fix this and make the javascript alert window display on the same web page only. Actually, I have tried some solutions like this..</p>
  
  <pre><code>if($fullName == "")
  {
    echo '&lt;script&gt;';
    echo 'alert("Full Name is required!")';
    echo 'window.location.href = "registeruser.php"';
    echo '&lt;/script&gt;';
  }
  </code></pre>