我写了一个函数" attempt_login1()"登录它工作正常。
但当我包含函数" login_count()"要计算登录总数(它在代码中注释掉了)它会给出错误
解析错误:语法错误,意外' $连接'第45行的F:\ XAMP1 \ htdocs \ sandbox \ test.php中的(T_VARIABLE)
我不确定是什么导致了这个错误。 谢谢你的帮助。
$username = "user123";
$password = "12345";
attempt_login($username, $password);
function attempt_login($username, $password){
$user = find_admin_by_username($username); //select user by username in database
$user_set = mysqli_fetch_assoc($user);
if($user_set){
$user_password = $user_set["hashed_password"];
$hashed_password = password_verify($password, $user_password);
if($hashed_password == true){
// login_count($user_set["id"], $user_set["login_count"]);
return $user_set;
}else{
return false;
}
}else{
return false;
}
}
function login_count($user_id, $count){
$global $connection;
$count = $count++;
$query2 = "UPDATE admins SET login_count = $count WHERE id = $user_id";
$result2 = mysqli_query($connection, $query2);
}
function find_admin_by_username($username){
global $connection;
$query = "SELECT * ";
$query .= "FROM admins ";
$query .= "WHERE username = '{$username}' ";
$query .= "LIMIT 1";
$user_set = mysqli_query($connection, $query);
confirm_query($user_set);
if($user_set){
return $user_set;
}else{
return NULL;
}
}
答案 0 :(得分:0)
你有拼写错误:
在$global $connection
之前, global $connection
应该global
没有美元。
答案 1 :(得分:0)
使用以下代码为您的函数login_count:
function login_count($user_id, $count){
global $connection;
$count = $count++;
$query2 = "UPDATE admins SET login_count = $count WHERE id = $user_id";
$result2 = mysqli_query($connection, $query2);
}
希望它会对你有所帮助:)。