我試圖做一個簡單的登錄,該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 {...}' –