我试图做一个简单的登录,该ID和密码的输入由用户与数据库中的数据PHP ID和密码验证
//getting the inputs
$checkid = $_POST["id"];
$checkpassword = md5($_POST["pass"]);
//getting the id and password of the id and password of the inputs
$query = "SELECT id, password FROM login WHERE id=$checkid AND password=$checkpassword";
$res = mysqli_query($link, $query);
$nres = mysqli_num_rows($res);
//$nres should be 0 if the user inputs the right id but the wrong password
//or viceversa, the only way that it $nres!=0 is that both inputs match the db, right?
if ($nres == 0) {
header('Location: http://localhost:8888/login/login_fail.php');
else
header('Location: http://localhost:8888/profile/profile.php');
exit();
这是行不通的比较,甚至如果我把正确的ID和数据库上的密码重定向到login_fail.php。 注意:它工作,如果我只是用他的ID和取出查询“,密码”“和密码= $ checkpassword”。帮助
添加引号'“SELECT ID,密码从登录WHERE ID = '$ checkid' 和密码='$ checkpassword ''''和一个旁注:不要使用'md5',现在用作密码存储是不安全的。 –
+1,并且还要注意,由于不对POST变量进行任何处理,因此您可以广泛应对SQL注入攻击。 – JBES
你也可以修正你的条件陈述的支撑。 'if {...} else {...}' –