Hello, I'm trying to make a login script but I'm stick with a problem:
<?php
session_start();
if (isset($_POST['username'])) {
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
$query = mysql_query("select id from users where
username = '$username' and
password = '$password'");
if (mysql_num_rows($query) == 0) {
header('Location: ?error');
exit();
}
// assign id to session
$_SESSION['id'] = mysql_result($query, 0, 'id');
mysql_query("UPDATE users SET last_activity = ".time()." WHERE ".$_SESSION['id']);
header("Location: /");
exit();
}
?>
The problem with this script is that it sets last_activity to current time on EVERY user.
Can't figure the problem out.
Some help would be greatly appricated, and yes I'm gonna look into password encrypting later :P
edit: found problem, should be mysql_query("UPDATE users SET last_activity = ".time()." WHERE id = ".$_SESSION['id']);