PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old October 24th, 2009, 09:19 PM
LLX LLX is offline
Contributing User
Click here for more information.
 
Join Date: Apr 2007
Location: Glendale, CA, USA
Posts: 1,270 LLX User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 10 h 6 m 51 sec
Reputation Power: 4
Send a message via AIM to LLX Send a message via Yahoo to LLX
Storing time stamp

no matter what i do i cant seem to get and store the timestamp in my database

this is my current attempt

$RegDate = DateTime::getTimestamp();
$update = mysql_query("UPDATE ".$dtable." SET LastOn = '$RegDate' WHERE UID ='".$_SESSION['UID']."'");


i have 2 time stamp fiend in my db

`RegDate` timestamp NOT NULL default CURRENT_TIMESTAMP,
`LastOn` timestamp NOT NULL default '0000-00-00 00:00:00',

Any ideas?
__________________
29 years of creative writing
13 years of HTML
10 years of Photoshop
6 years of PHP/MySQL
And I never knew Photoshop could do HTML until 2004!
You learn something new every day.

Reply With Quote
  #2  
Old October 25th, 2009, 01:11 AM
IAmALlama IAmALlama is offline
Me
Click here for more information. Click here for more information
Click here for more information
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 1,937 IAmALlama User rank is Private First Class (20 - 50 Reputation Level)IAmALlama User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 5 Days 1 h 54 m 18 sec
Reputation Power: 4
well what does DateTime::getTimestamp() return? double check the query after built before running it to make sure it looks like you think it should. And try to echo out mysql_error() after the query to see if there is an error. I guess you could also replace the variables with the actual values to see if it is the database or one of the vars.

Reply With Quote
  #3  
Old October 25th, 2009, 01:19 AM
LLX LLX is offline
Contributing User
Click here for more information.
 
Join Date: Apr 2007
Location: Glendale, CA, USA
Posts: 1,270 LLX User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 10 h 6 m 51 sec
Reputation Power: 4
Send a message via AIM to LLX Send a message via Yahoo to LLX
Quote:
Originally Posted by IAmALlama
well what does DateTime::getTimestamp() return? double check the query after built before running it to make sure it looks like you think it should. And try to echo out mysql_error() after the query to see if there is an error. I guess you could also replace the variables with the actual values to see if it is the database or one of the vars.


Call to undefined method DateTime::gettimestamp()

byt i got the name right from php.net

*sigh*

Reply With Quote
  #4  
Old October 25th, 2009, 03:52 AM
jamestrowbridge jamestrowbridge is offline
Contributing User
Click here for more information.
 
Join Date: Jul 2008
Location: Cleveland, Ohio, USA
Posts: 411 jamestrowbridge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 Days 18 h 54 m 24 sec
Reputation Power: 2
PHP Code:
 $update mysql_query("UPDATE ".$dtable." SET LastOn = FROM_UNIXTIME(".time().") WHERE UID ='".$_SESSION['UID']."'"); 
__________________
Sir, a desire of knowledge is the natural feeling of mankind; and every human being, whose mind is not debauched, will be willing to give all that he has to get knowledge.

Reply With Quote
  #5  
Old October 25th, 2009, 04:02 AM
IAmALlama IAmALlama is offline
Me
Click here for more information. Click here for more information
Click here for more information
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 1,937 IAmALlama User rank is Private First Class (20 - 50 Reputation Level)IAmALlama User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 5 Days 1 h 54 m 18 sec
Reputation Power: 4
And the new datetime class is available in php as of version 5.2.0 and a lot of the methods such as getTimestamp was added in 5.3.0. So unless you are using the most recent version of php that method of the class won't work.

Reply With Quote
  #6  
Old October 25th, 2009, 05:38 PM
LLX LLX is offline
Contributing User
Click here for more information.
 
Join Date: Apr 2007
Location: Glendale, CA, USA
Posts: 1,270 LLX User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 10 h 6 m 51 sec
Reputation Power: 4
Send a message via AIM to LLX Send a message via Yahoo to LLX
Quote:
Originally Posted by IAmALlama
And the new datetime class is available in php as of version 5.2.0 and a lot of the methods such as getTimestamp was added in 5.3.0. So unless you are using the most recent version of php that method of the class won't work.


that must be it

while the host lists "PHP 5" phpmy admin lists this

4.1.22

Reply With Quote
  #7  
Old October 25th, 2009, 06:29 PM
LLX LLX is offline
Contributing User
Click here for more information.
 
Join Date: Apr 2007
Location: Glendale, CA, USA
Posts: 1,270 LLX User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 10 h 6 m 51 sec
Reputation Power: 4
Send a message via AIM to LLX Send a message via Yahoo to LLX
Quote:
Originally Posted by jamestrowbridge
PHP Code:
 $update mysql_query("UPDATE ".$dtable." SET LastOn = FROM_UNIXTIME(".time().") WHERE UID ='".$_SESSION['UID']."'"); 


i'll take your word for it that thats works in a update as i haven't had a chance to test it but what about in this instance since a var assignment doesn't work

$RegDate = FROM_UNIXTIME(".time().");
$querystring1="INSERT INTO Users (Name, Username, Password, Email, GroupID, Baned, SysEmails, RegDate, Status) VALUES ('$name', '$username', '$password', '$email', 1, 0, 1, '$RegDate', 1)";

Reply With Quote
  #8  
Old October 25th, 2009, 08:33 PM
IAmALlama IAmALlama is offline
Me
Click here for more information. Click here for more information
Click here for more information
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 1,937 IAmALlama User rank is Private First Class (20 - 50 Reputation Level)IAmALlama User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 5 Days 1 h 54 m 18 sec
Reputation Power: 4
from_unixtime() is a mysql function.

http://dev.mysql.com/doc/refman/5.1...-functions.html

you wouldn't be able to use it in php directly. if you did want to get the timestamp in php, you would have to use the date() function and create a mysql timestamp using that.

Reply With Quote
  #9  
Old October 25th, 2009, 09:04 PM
LLX LLX is offline
Contributing User
Click here for more information.
 
Join Date: Apr 2007
Location: Glendale, CA, USA
Posts: 1,270 LLX User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 10 h 6 m 51 sec
Reputation Power: 4
Send a message via AIM to LLX Send a message via Yahoo to LLX
Quote:
Originally Posted by IAmALlama
from_unixtime() is a mysql function.

http://dev.mysql.com/doc/refman/5.1...-functions.html

you wouldn't be able to use it in php directly. if you did want to get the timestamp in php, you would have to use the date() function and create a mysql timestamp using that.


you know i really hate the timestamp...

what about just putting it directly into the insert query liek the update

Reply With Quote
  #10  
Old October 25th, 2009, 10:57 PM
jamestrowbridge jamestrowbridge is offline
Contributing User
Click here for more information.
 
Join Date: Jul 2008
Location: Cleveland, Ohio, USA
Posts: 411 jamestrowbridge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 Days 18 h 54 m 24 sec
Reputation Power: 2
Yeah, it's the same thing, you just have to pay attention to whether you're in MySQL or PHP:

PHP Code:
 $sql_query "SELECT * FROM table WHERE timestamp <= FROM_UNIXTIME(".time().")"


This whole part here is SQL:
PHP Code:
 SELECT FROM table WHERE timestamp <= FROM_UNIXTIME


until you end the quotes, and add the . then it goes to PHP (where you have the PHP time() function) then you stop PHP with another . and restart the quotes to start the MySQL again, end the FROM_UNIXTIME MySQL function with a ) and end the quotes, and end the PHP statement with a ;

So you end up with PHP:
PHP Code:
 time() 


and some more MySQL:
PHP Code:



In an INSERT statement you'd do:
PHP Code:
 $sql_insert "INSERT INTO Persons (FirstName, LastName, time) VALUES ('Peter', 'Griffin', FROM_UNIXTIME(".time().")"


notice in the above INSERT statment that there is no single quote around the FROM_UNIXTIME() funtion.

Reply With Quote
  #11  
Old October 28th, 2009, 11:33 AM
LLX LLX is offline
Contributing User
Click here for more information.
 
Join Date: Apr 2007
Location: Glendale, CA, USA
Posts: 1,270 LLX User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 10 h 6 m 51 sec
Reputation Power: 4
Send a message via AIM to LLX Send a message via Yahoo to LLX
Quote:
Originally Posted by jamestrowbridge
Yeah, it's the same thing, you just have to pay attention to whether you're in MySQL or PHP:

PHP Code:
 $sql_query "SELECT * FROM table WHERE timestamp <= FROM_UNIXTIME(".time().")"


This whole part here is SQL:
PHP Code:
 SELECT FROM table WHERE timestamp <= FROM_UNIXTIME


until you end the quotes, and add the . then it goes to PHP (where you have the PHP time() function) then you stop PHP with another . and restart the quotes to start the MySQL again, end the FROM_UNIXTIME MySQL function with a ) and end the quotes, and end the PHP statement with a ;

So you end up with PHP:
PHP Code:
 time() 


and some more MySQL:
PHP Code:



In an INSERT statement you'd do:
PHP Code:
 $sql_insert "INSERT INTO Persons (FirstName, LastName, time) VALUES ('Peter', 'Griffin', FROM_UNIXTIME(".time().")"


notice in the above INSERT statment that there is no single quote around the FROM_UNIXTIME() funtion.


I havent tested a new registration but i tried to test a update and nothing happened

$update = mysql_query("UPDATE Users SET LastOn = FROM_UNIXTIME(".time().") WHERE UID = ".$_SESSION['UID']."")or die(mysql_error());

still leaves "LastOn" blank

Reply With Quote
  #12  
Old October 28th, 2009, 12:03 PM
IAmALlama IAmALlama is offline
Me
Click here for more information. Click here for more information
Click here for more information
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 1,937 IAmALlama User rank is Private First Class (20 - 50 Reputation Level)IAmALlama User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 5 Days 1 h 54 m 18 sec
Reputation Power: 4
double check that the session id you are trying to pass is entered in the database. echo out the query before running it to make sure it matches exactly what you want.

Reply With Quote
  #13  
Old October 28th, 2009, 12:17 PM
LLX LLX is offline
Contributing User
Click here for more information.
 
Join Date: Apr 2007
Location: Glendale, CA, USA
Posts: 1,270 LLX User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 10 h 6 m 51 sec
Reputation Power: 4
Send a message via AIM to LLX Send a message via Yahoo to LLX
Quote:
Originally Posted by IAmALlama
double check that the session id you are trying to pass is entered in the database. echo out the query before running it to make sure it matches exactly what you want.


Ok i found the problem:
Basicly because of my if/else loops i needed to reconnect to my database at the update portion.

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > Storing time stamp


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek