Forum Moderators: coopster

Message Too Old, No Replies

Login Script Problem!

         

tunnelvision

10:42 pm on Mar 1, 2005 (gmt 0)

10+ Year Member



Hello All,
Ive created a login script which works fine. So i decided to add a piece of code which adds the login time, date and the ip of the user into the database. This is the code i am using:

$ip = $_SERVER["REMOTE_ADDR"];
$time = date("H:i:s");
$date = date("j-M-Y");

$stat = mysql_fetch_array(mysql_query("SELECT * FROM members WHERE username='$username1' AND password='$password1'"));
mysql_query("UPDATE members SET (login_time, login_date, ip) VALUES ('$time', '$date', '$ip') WHERE id=$stat[id]");

When i run the script it logs me in but dosn't enter the data into the database. I was hopein some on this forum can point out where am goin wrong.

Cheers
<!-- tunnelvision -->

crxchaos

12:17 am on Mar 2, 2005 (gmt 0)

10+ Year Member



tunnelvision,

I think the problem lies with the array reference, the 'id' should be in quotes. Try this:


mysql_query("UPDATE members SET (login_time, login_date, ip) VALUES ('$time', '$date', '$ip') WHERE id=".$stat['id']);

frizhard

5:27 pm on Mar 2, 2005 (gmt 0)

10+ Year Member



Does that query really work?

I would use this instead:

mysql_query("UPDATE members SET login_time='{$time}', login_date='{$date}', ip='{$ip}' WHERE id={$stat['id']}");

And I would also make sure $stat['id'] contains a valid id before updating

Hope this can help you