Dates and Databases

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
stevenpepe
Forum Newbie
Posts: 2
Joined: Sat Mar 27, 2010 7:36 am

Dates and Databases

Post by stevenpepe »

Hello,

I am a midlevel PHP developer building an ecommerce site. I am adding a module that allows the admin to view registered customers and the time and date they last logged in.

The date/time is inserted into the 'customers' table, in a datetime column. When the customer logs in, this information is UPDATED in the database along with the cookie setting.

The UPDATE works fine and is inserted into the customer's datetime column. However, when I test it with another customer account, the previously logged in customer has their table updated back to the 0:00:00 datetime default. The default field is empty on the database, so that is not selected.

The UPDATE is written as:

sql = "UPDATE customers SET loggedin = NOW() WHERE email='$email'";
(rest of query goes here).

I have also tried creating a date variable with a date function with the same results. ($date = date(params here))

My first guess is the cookie is still recognizing the logged in email account. But if so, why would it UPDATE back to zero. It should not update at all, leaving the datetime in place so the admin can view this information. Of course, when the customer logs in again, the new datetime will reflect that as well.

I have tried the update on the redirect page, after the cookie is set, by grabbing the customer's ID and updating then. Still the same result.

I hope this is clear and I thank you all for your assistance.

Steve
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Dates and Databases

Post by Benjamin »

:arrow: Moved to PHP - Code
Post Reply