我知道我可以连接到数据库。在我修改我的代码之前,我已经检查过了。
当管理员登录时,我想重定向到,tableedit.php
但如果用户不是我想重定向到的管理员tableuser.php
。
这是错误:
警告:mysql_fetch_array() 期望参数 1 是资源,第 47 行 C:\xampp\htdocs\joy\inventory\login.php 中给出的字符串查询失败
这是代码:
//Create query
$qry="SELECT * FROM user WHERE username='$username' AND password='".md5($_POST['password'])."'";
while($row=mysql_fetch_array($qry));
$result = $row['username'];
{
//Check whether the query was successful or not
if($result) {
if(mysql_num_rows($result)== 'admin'){
session_regenerate_id();
$member = mysql_fetch_assoc($result);
$_SESSION['SESS_MEMBER_ID'] = $member['id'];
$_SESSION['SESS_FIRST_NAME'] = $member['username'];
$_SESSION['SESS_LAST_NAME'] = $member['password'];
session_write_close();
header("location: tableedit.php");
exit();
}
elseif(mysql_num_rows($result) != 'admin') {
//Login Successful
session_regenerate_id();
$member = mysql_fetch_assoc($result);
$_SESSION['SESS_MEMBER_ID'] = $member['id'];
$_SESSION['SESS_FIRST_NAME'] = $member['username'];
$_SESSION['SESS_LAST_NAME'] = $member['password'];
session_write_close();
header("location: tableuser.php");
exit();
} else {
//Login failed
$errmsg_arr[] = 'Username and password not found.';
$errflag = true;
if($errflag) {
$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
session_write_close();
header("location: index.php");
exit();
}
}
} else {
die("Query failed");
}}