gpt4 book ai didi

php - 如何向用户显示上次访问情况

转载 作者:行者123 更新时间:2023-11-29 12:08:23 24 4
gpt4 key购买 nike

我想显示用户上次访问的时间,我在一些互联网帮助下制作了这个脚本,但当然它不起作用。

$sql="update users set last_visit = NOW() where id = ".$_SESSION['userid'].
if($sql === false)
{
echo 'Query mislukte bij regel '. __LINE__ . '<br>';
}

有人知道我做错了什么吗?

最佳答案

正如您要求的示例,请检查此代码:-

 <?php
session_start(); // start session to get SESSION variable value
error_reporting(E_ALL); // catch all type of errors
ini_set('display_errors',1); // display those errors

$conn = mysqli_connect('servername','username','password','databasename'); // fill your database details here

$user_id = mysqli_real_escape_string($conn,$_SESSION['userid']);// prevent form SQL injection
$last_visit = date('Y-m-d H:i:s'); // you can change date format according to your wish

$sql = "UPDATE users SET last_visit = '". $last_visit ."' WHERE id = '". $user_id ."'"; // change in query

$result = mysqli_query($conn,$sql) or die(mysqli_error($conn)); // execute query and catch error if any happen

if($result){
echo "Record updated successfully";
}else{
echo 'Some error occur while updating. Please try again.';
}
?>

注意:- 只需输入您的数据库凭据即可继续。

关于php - 如何向用户显示上次访问情况,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31093588/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com