[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

MySql Update Query

Posted on 2011-03-06
2
Medium Priority
?
465 Views
Last Modified: 2012-05-11
I am trying to update a record in a table called 'user_access' to record the last login time in a field called 'last_login'. I am trying the query below without luck.

Can anyone see where I am going wrong.
mysql_query("UPDATE user_access SET last_login = '$date' WHERE user_id = '$username'")or die(mysql_error());

Open in new window

0
Comment
Question by:abdulv
2 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 35047038
what is the problem?
note that date fields MUST have format YYYY-MM-DD to be updated correctly ...
0
 
LVL 3

Accepted Solution

by:
wwwdeveloper2 earned 2000 total points
ID: 35048472

MySQL does have a curdate() function that will automatically grab the date,so you won't have to do it with PHP:

mysql_query("UPDATE user_access SET last_login = CURDATE() WHERE user_id = '$username'")or die(mysql_error());

Here is a couple of examples:

http://www.tizag.com/mysqlTutorial/mysql-date.php
http://www.ntchosting.com/mysql/insert-date.html
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Lotus Notes has been used since a very long time as an e-mail client and is very popular because of it's unmatched security. In this article we are going to learn about  RRV Bucket corruption and understand various methods to Fix "RRV Bucket Corrupt…
The viewer will learn how to dynamically set the form action using jQuery.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month17 days, 23 hours left to enroll

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question