Javascript PHP标头位置函数在表单中不起作用
我正在为我的网站做一份登记表。我正在使用下面的代码。所有错误处理程序都可以正常工作,因为它正在将用户添加到我的数据库中。我想增加一个开始。我使用升华文本插件删除了所有空白。我尝试使用javascript而不是php(top.window)。我还尝试使用完整的url,而不仅仅是目录。但当我点击提交时,它不会将我重定向到我放在位置后面的地址。当我点击按钮时,它会将我带到这个php文件,但不会将我重定向回注册页面,这是一个单独的文件(我知道有很多类似的问题被问到,但它们似乎不适合我的情况)。 有人知道如何解决这个问题吗?Javascript PHP标头位置函数在表单中不起作用,javascript,php,html,Javascript,Php,Html,我正在为我的网站做一份登记表。我正在使用下面的代码。所有错误处理程序都可以正常工作,因为它正在将用户添加到我的数据库中。我想增加一个开始。我使用升华文本插件删除了所有空白。我尝试使用javascript而不是php(top.window)。我还尝试使用完整的url,而不仅仅是目录。但当我点击提交时,它不会将我重定向到我放在位置后面的地址。当我点击按钮时,它会将我带到这个php文件,但不会将我重定向回注册页面,这是一个单独的文件(我知道有很多类似的问题被问到,但它们似乎不适合我的情况)。 有人知道
if (isset($_POST['submit'])){
include_once 'db.php';
$uid = mysqli_real_escape_string($conn, $_POST['uid']);
$pwd = mysqli_real_escape_string($conn, $_POST['pwd']);
$email = mysqli_real_escape_string($conn, $_POST['email']);
//error handlers
//Check for empty fields
if (empty($uid) || empty($pwd) || empty($email)) {
header("Location : /login/register.php?signup=empty");
exit();
} else{
//Check if input characters are valid
if (!preg_match("/^[a-zA-Z]*$/", $uid)) {
header('Location: /login/register.php?signup=invalid');
exit();
} else {
//Check if email is valid
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
header('Location : /login/register.php?signup=email');
exit();
} else {
$sql = "SELECT * FROM users WHERE user_uid='$uid'";
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);
if ($resultCheck > 0) {
header('Location : /login/register.php?signup=usertaken');
exit();
} else {
//Hashing the password
$hashedPwd = password_hash($pwd, PASSWORD_DEFAULT);
//Insert the user into the databse
$sql = "INSERT INTO users (user_uid, user_pwd, user_email) VALUES ('$uid', '$hashedPwd', '$email');";
mysqli_query($conn, $sql);
header('Location : /login/register.php?signup=success');
exit();
}
}
}
}
} else {
header('Location : /login/register.php');
exit();
}
已解决-删除Nigel Ren回答“位置”后的空格尝试使用绝对URI
$host = $_SERVER['HTTP_HOST'];
header("Location: ".$host."/login/register.php?signup=empty");
确保在位置之后和之前没有空格:
header('Location : /login/register.php');
应该是
header('Location: /login/register.php');
将所有标题替换为location.assign
header('Location : /login/register.php');
取代
echo "<script>location.assign('/login/register.php')</script>";
echo“location.assign('/login/register.php')”;
使用location assign后,可能会出现问题sol..只需添加域名也可以此类型uy无法定位您的域任何错误消息?如标题已发送或类似内容检查“db.php”@AlanLin中是否有尾随空格,如果您对此满意,是否可以将其标记为接受答案(如果您不确定如何标记,请检查)