我正在尝试创建一个自动注销系统,当页面处于非活动状态时会自动注销系统,我是新手,当我向登录页面添加代码时,我收到了这些警告
Warning: mysql_query() expects parameter 1 to be string, resource given in C:\xampp\htdocs\how are things\admin panel\login.php on line 80
Warning: mysql_num_rows() expects parameter 1 to be resource, null given in C:\xampp\htdocs\how are things\admin panel\login.php on line 81
第 80 行和第 81 行的代码分别如下
if($no_rows > 0){
while($resGetAdmin = mysql_fetch_assoc($rs_user))
这是我添加的代码
$rs_user= mysql_query($check_login);
$no_rows = mysql_num_rows($rs_user);
if($no_rows > 0){
while($resGetAdmin = mysql_fetch_assoc($rs_user)){
$selQuery="select * from login where user_id=".$resGetAdmin['user_id'] ." AND loginDate ='$current_date'";
$rgetData= mysql_query($selQuery);
$num_login = getSqlNumber($selQuery);
if($num_login==0) {
$insQuery= "insert into login (user_id,loginTime,loginDate,count) values (".$resGetAdmin['user_id'].",'$current_time','$current_date',1)";
$login_user= mysql_query($insQuery);
$insert_id=mysql_insert_id();
$_SESSION['loginTime']=$current_time;
}else{
$count = mysql_result($rgetData,0,’count’);
$count = $count+1;
$updateQuery= "update login set loginTime='$current_time' ,loginDate='$current_date' , count ='$count' where user_id=".$resGetAdmin['user_id'] ." AND loginDate='$current_date'";
$login_user= mysql_query($updateQuery) or mysql_error();
$_SESSION['loginTime']=$current_time;
}
$_SESSION['user_id']=$resGetAdmin['user_id'];
header("Location: index.php");
exit;
}
}
这是我添加上面代码之前的原始登录页面
<?php
if(isset($_POST['submit'])){
$username = $_POST['username'];
$password =($_POST['password']);
$hash_password = md5($password);
$hash_password1 = sha1($hash_password);
$hash_password2 = crypt($hash_password1,"st");
$hash_password3 = hash("sha512",$hash_password2);
$guess = $_POST['captcha'];
$real = (isset($_SESSION['real'])) ? $_SESSION['real'] : "";
if (empty($guess))
{
die("Please enter the correct CAPTCHA.<br>");
}
if (!empty($guess) && $guess !== $real)
{
die("Please enter the correct CAPTCHA.<br>");
}
if(empty($username) or empty($password)){
echo "<p>fields empty !</p>";
}
else {
$check_login = mysql_query("SELECT id, type FROM users WHERE username='$username' AND password='$hash_password3'");
if(mysql_num_rows($check_login) == 1) {
$run = mysql_fetch_array($check_login);
$user_id = $run['id'];
$type = $run['type'];
if($type == 'd'){
echo "<p> Your Account is deactivated byt the site admin!</p>";
} else {
$_SESSION['user_id'] = $user_id;
header('location: index.php');
}
} else {
echo "<p> User Name or Password incorrect!</p>";
} }
}
?>
我将整个代码粘贴在登录页面上,但我离开了 timeout.php 页面,在此先感谢大家