//mysql connection
$com = mysql_connect("localhost","root","");
mysql_select_db("usersystem");
if(isset($_POST['Submit'])) {
$userName = $_POST['userName'];
$passWord = $_POST['passWord'];
$result = mysql_query("SELECT userID FROM tbl_users WHERE userName='$userName' AND passWord='$passWord' LIMIT 1");
if(mysql_num_rows($result)==1) {
//"login success";
$data = mysql_fetch_array($result,1);
$_SESSION['userID'] = $data['userID'];
header("location: dashboard.php");
}
else {
//login failed
$error = "login failed";
}
我在phpMyAdmin中设置了一个数据库,我的数据库中有2个用户。但是,当我启动我的网站时,我输入两个用户的用户名和密码,它的工作原理!但是,如果我输入用户名和密码的随机单词,它仍然会登录,我很困惑。请帮帮我。
答案 0 :(得分:5)
if(mysql_num_rows($query)==1){
//"login success";
$data=mysql_fetch_array($query,0);
$_SESSION['userID']=$data['userID'];
header("location:dashboard.php");
}
将零更改为1并且不使用mysql_已弃用使用mysqli或PDO
$query=mysql_query("SELECT userID FROM tbl_users WHERE userName='$userName' AND passWord='$passWord' limit 1 ", $com);
并改变这一点。
答案 1 :(得分:2)
答案 2 :(得分:0)
$query
是一个空变量。
转到
$result = mysql_query("SELECT userID FROM tbl_users WHERE userName='$userName' AND passWord='$passWord' LIMIT 1");
if(mysql_num_rows($result))
{
//"login success";
$data = mysql_fetch_array($result,0);
...