为什么php中的重定向代码会自动工作?
我想写一些代码来登录用户,当用户尚未在数据库中注册时,将其发送到“register.php”页面。我使用了header('Location:register.php')代码,但当我刷新页面时,没有任何单击注册按钮,它会自动转到该页面,并且登录表单没有显示 以下是我的“login.php”代码:为什么php中的重定向代码会自动工作?,php,html,login,header,Php,Html,Login,Header,我想写一些代码来登录用户,当用户尚未在数据库中注册时,将其发送到“register.php”页面。我使用了header('Location:register.php')代码,但当我刷新页面时,没有任何单击注册按钮,它会自动转到该页面,并且登录表单没有显示 以下是我的“login.php”代码: 无标题文件 我知道“connect_inc.php”没有问题,它成功地连接到数据库。我试图删除其他不相关的代码,如“”,但没有任何帮助。 任何帮助都将不胜感激。尝试使用此 而不是 <input
无标题文件
我知道“connect_inc.php”没有问题,它成功地连接到数据库。我试图删除其他不相关的代码,如“”,但没有任何帮助。
任何帮助都将不胜感激。尝试使用此
而不是
<input type="submit" value="register" onClick="<?php header('Location: register.php'); ?>" name="btnregister">`
onClick
需要一个javascript函数,而不是PHP。试一试
window.location='register.php'
因此,在这种情况下:
从提交字段中完全删除onclick函数,然后添加
header('Location:register.php');
给你
if($query_num_rows == 0){
echo 'invalid username or password! if you have not registered yet please do it!';
header('Location:register.php');
}
我使用了你的代码,但问题仍然存在!似乎问题不在“标题…”上。我很困惑“选择*from作为登录名,其中用户名='$username'和密码='$hash\u passwword'”代码>…您不需要使用“…我需要用数据库中的值检查输入的值,为什么我不需要它?好的,但我不知道如何解决此问题!非常感谢。
header('Location:register.php');
if($query_num_rows == 0){
echo 'invalid username or password! if you have not registered yet please do it!';
header('Location:register.php');
}