?
Solved

MySql Update Query

Posted on 2011-03-06
2
Medium Priority
?
454 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insi…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

765 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