Jump to content

Setting the current date in mySQL


CincoPistolero

Recommended Posts

I'm trying to set a mySQL DB field lastLoginDate with the current date. Below is my code.

$date = date('d.m.Y');
$update_login = $db_object->query("UPDATE users SET  lastLoginDate='$date' logged_in = '1' WHERE userName = '".$_POST['uname']."'");

 

Nothing gets put in the DB.

Link to comment
https://forums.phpfreaks.com/topic/38266-setting-the-current-date-in-mysql/
Share on other sites

<?php

$userName=addslashes($_POST['userName']);
$date=addslashes($_POST['date']);

$date = date("d-m-Y");

$update_login = "UPDATE `users` SET  `lastLoginDate`='$date' `logged_in` = '1' WHERE 
`userName` = '$userName' ";

$result_insert=mysql_query($update_login);

?>

This set my date in the DB, but set it to '2013-02-20'. Below is what I have now.

$date = date('d-m-Y');
$update_login = $db_object->query("UPDATE users SET  lastLoginDate='$date' WHERE userName = '".$_POST['uname']."'");
$result_insert=mysql_query($update_login);

 

I had been missing the $result_insert line

 

Any hints on why the date is wrong?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.