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

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?

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.