Solved

MySql Update Query

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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
A company’s centralized system that manages user data, security, and distributed resources is often a focus of criminal attention. Active Directory (AD) is no exception. In truth, it’s even more likely to be targeted due to the number of companies …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

707 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