This topic is locked

Problems with timestamp

6/20/2006 3:35:34 PM
PHPRunner General questions
J
Jepsen author

I have a problem killing me. I want to log who and when people login. For that purpose I have a table:
id int (masterkey with autoinc)

user VARCHAR(50)

ip VARCHAR(50)

when VARCHAR(50)
On successfull login the following code works fine:
function AfterSuccessfulLogin()

{

//** Insert a record into another table ****

global $conn;

$Username = @$_SESSION["UserID"];

$IP = $_SERVER["REMOTE_ADDR"];

$strSQLInsert = "insert into `_vaben_LogUser` (user, ip) values ('$Username', '$IP')";

db_exec($strSQLInsert,$conn);

}
But this code causes a PHP error:
function AfterSuccessfulLogin()

{

//** Insert a record into another table ****

global $conn;

$Username = @$_SESSION["UserID"];

$IP = $_SERVER["REMOTE_ADDR"];

$when = date('Y-m-d H:i');

$strSQLInsert = "insert into `_vaben_LogUser` (user, ip, when) values ('$Username', '$IP', '$when')";

db_exec($strSQLInsert,$conn);
What is wrong?
Rgds

Morten Jepsen

prleo1 6/20/2006

It might help to change the "when" column type to a timestamp.
Try using NOW() in your insert statement as shown below.
..then, taylor the date format via SQL.
global $conn;

$ip = $_SERVER["REMOTE_ADDR"];

$name = @$_SESSION["UserID"];

$accesstype = "Login";

$strSQLInsert = "insert into audit (ip_address, username, access_type, access_time) values ('$ip', '$name','$accesstype',NOW())";

db_exec($strSQLInsert,$conn);

}
Let me know if that helps.

J
Jepsen author 6/20/2006

Thanks for your reply.
I made the field a timestamp and inserted your code. Still got a parse error.
However, something unexpected happened. When you make a field "TIMESTAMP" and you do not allocate a variable to it, it automatically plases a timestamp in the field. Consequently, just making the field timestamp did the trick withour altering the code.
Thanks for your help.
Morten B Jepsen