Javascript警报窗口重定向到另一个页面

前端之家收集整理的这篇文章主要介绍了Javascript警报窗口重定向到另一个页面前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
<?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 == "")
  {

?>
    <script>
      alert("Full Name is required!");
      window.location.href = "registeruser.PHP";
    </script>
<?PHP
  }

    else
    {
      if ($userName == "")
      {
?>
        <script>
          alert("Invalid username!");
          window.location.href = "registeruser.PHP";
        </script>
 <?PHP     
      }

        else
        {
          if($userName == $result['USERNAME'])
          {
?>
            <script>
              alert("Username already exists!");
              window.location.href = "registeruser.PHP";
            </script>
<?PHP
          }

            else
            {
              if ($emailAdd == $result['EMAIL']) 
              {
?>
                <script>
                  alert("Email address is required!");
                  window.location.href = "registeruser.PHP";
                </script>
<?PHP
              }

                else
                {
                  if ($passWord == "")
                  {
?>
                    <script>
                      alert("Username is required!");
                      window.location.href = "registeruser.PHP";
                    </script>
 <?PHP     
                  }

                    else
                    {
                      if($_POST['password']==$_POST['confirmpass'])
                      {
                        MysqL_query("INSERT INTO users (FULLNAME,USERNAME,EMAIL,PASSWORD) 
                        VALUES ('$fullName','$userName','$emailAdd','$passWord')" );
                        MysqL_close();
?>    
                        <script>
                          alert("Registered Successfully!");
                          window.location.href = "index.PHP";
                        </script>
<?PHP
                      }

                        else
                        {
?>
                          <script>
                            alert("Password and Confirm Password do not match");
                            window.location.href = "registeruser.PHP";
                          </script>
<?PHP
                        }
                    }
                }
            }
        }
    }   

?>

工作正常但问题是:警报窗口显示给另一个网页而不在网页内可以,但是将用户指向另一个网页,而不在其内部看起来很糟糕.如果您可以帮助我,如何解决这个问题,并使JavaScript警报窗口只显示在同一个网页上.其实我已经尝试过这样的一些解决方

if($fullName == "")
{
  echo '<script>';
  echo 'alert("Full Name is required!")';
  echo 'window.location.href = "registeruser.PHP"';
  echo '</script>';
}

解决方法

使用基本URL,然后将您的自定义路径粘贴到您的页面,如:
<?PHP
if($fullName == "")
{
?>
  <script>
   var MyBaseURL = <?PHP echo BASE_URL_CONSTANT?>
   var customURL = MyBaseURL."/registeruser.PHP";
   alert("Full Name is required!");
   window.location.href = customURL;
  </script>
<?PHP
}
?>

并且你应该避免回声脚本,使用带有附加的PHP标签的常规脚本块.

猜你在找的JavaScript相关文章