微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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标签的常规脚本块.

原文地址:https://www.jb51.cc/js/151683.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐