tags:

views:

88

answers:

1

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']);

A: 

You can use the mysql function now() as opposed to the php function time() - not that it makes a huge difference but its slightly neater as you don't have to break the string to do it. E.g. "Update tablename set time=now() where condition"

Meep3D