<?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>'; }