Solved

MySql Update Query

Posted on 2011-03-06
2
427 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 142

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 500 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

786 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