0

How can I add the current date and time to a specific row within the database. I'm working on a project that stores the date and time of when the user last logged online.

I've currently got

$date = date('Y-m-d H:i:s');
$query = "UPDATE Login SET Last Logged='$date' WHERE Email='$email'";
$results = mysqli_query($conn, $query);

It current stores 0000-00-00.

Is this along the right lines? or have I gone on off the beaten track?

I've look for other questions asked, but couldn't see any that may answer this.

John Conde
  • 217,595
  • 99
  • 455
  • 496
Alex Probert
  • 127
  • 1
  • 10
  • 1
    `Last Logged` has a space in it. You need to either change it so it does not or wrap it in backticks. Also, this would be simpler if you just let MySQL set the date for you by using CURRENT_DATE. – John Conde Jun 07 '20 at 16:07
  • 3
    this code is **vulnerable to sql injection** please read https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php – nbk Jun 07 '20 at 16:16

0 Answers0