title: How to insert time of user's logout in database?
body: <p>I successfully made the code for logging in...when user logs in, the time of logging in is written in database. </p>
  
  <pre><code>session_start();
      $query = mysql_query("SELECT * FROM users");
      $result = mysql_fetch_array($query);
  
  
      if(!empty($_POST['username']) &amp;&amp; !empty($_POST['password'])){           
          $username = ($_POST['username']);
          $password = ($_POST['password']);           
          $username = stripslashes($username);
          $password = stripslashes($password);            
          $username = mysql_real_escape_string($username);
          $password = mysql_real_escape_string($password);            
          $_SESSION['username'] = $username;
          $_SESSION['password'] = $password;
  
  $result = mysql_query("SELECT * FROM users WHERE username = '$username' AND status = '1'"); 
   if(mysql_num_rows($result) == 1) {
                  mysql_query("INSERT INTO entry(id, username_id, entry_time) VALUES ('', 'bkrpan', NOW()) "); 
                  header("Location: admin.php"); 
                  exit; }
  
          $result = mysql_query("SELECT username FROM users WHERE username = '$username' AND password = '$password'");
              if(mysql_num_rows($result) == 1) {
                  mysql_query("INSERT INTO entry(id, username_id, entry_time) VALUES ('', '$username', NOW()) "); 
              $_SESSION['username'] = $username;
              $_SESSION['password'] = $password;
              header("Location: users.php");
              exit; }
              echo "Login failed! You will be redirected.";
              echo "&lt;meta http-equiv=\"refresh\" content=\"2;URL=index.php\"&gt;";
              } 
  
      else {
          echo "Login failed! You will be redirected.";
          echo "&lt;meta http-equiv=\"refresh\" content=\"2;URL=index.php\"&gt;";
      }
  
       session_destroy();
  </code></pre>
  
  <p>but...now I don't know how to make the code for logout.
  This is something that I made, but it's not working.</p>
  
  <pre><code> &lt;?php
   mysql_connect("localhost", "root", "") or die("cannot connect"); 
   mysql_select_db("zavrsni_rad") or die("cannot select DB");
   session_start();
   $username = $_SESSION['username'];
   $sql = "SELECT * FROM users WHERE username = ".$username." AND password = ".$password;
   $result = mysql_query($sql); 
   if(mysql_num_rows($result) == 1) {
  $sql_2 = "INSERT INTO entry(username_id, entry_time) VALUES (".$username.", NOW()        )";
  mysql_query($sql_2); 
   }
  session_destroy();
   header("location: index.php");
   ?&gt;
  </code></pre>