duanlaofu4108 2015-06-27 21:14
浏览 13
已采纳

如何向用户显示上次访问[关闭]

I want to display the time of the last visit of an user, I made this script with some internet help but of-course it doesn't work.

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

Someone know what i'm doing wrong?

  • 写回答

1条回答 默认 最新

  • dongluyi5123 2015-06-27 21:33
    关注

    As you asked for an example, check this code:-

     <?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.';
          }
    ?>
    

    Note:- just put your database credentials and go-on.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?