|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
|
#2
|
|||
|
|||
|
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.
|
|
#3
|
|||
|
|||
|
Quote:
Call to undefined method DateTime::gettimestamp() byt i got the name right from php.net *sigh* |
|
#4
|
|||
|
|||
|
PHP Code:
__________________
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. |
|
#5
|
|||
|
|||
|
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.
|
|
#6
|
|||
|
|||
|
Quote:
that must be it while the host lists "PHP 5" phpmy admin lists this 4.1.22 |
|
#7
|
|||
|
|||
|
Quote:
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)"; |
|
#8
|
|||
|
|||
|
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. |
|
#9
|
|||
|
|||
|
Quote:
you know i really hate the timestamp... what about just putting it directly into the insert query liek the update |
|
#10
|
|||
|
|||
|
Yeah, it's the same thing, you just have to pay attention to whether you're in MySQL or PHP:
PHP Code:
This whole part here is SQL: PHP Code:
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:
and some more MySQL: PHP Code:
In an INSERT statement you'd do: PHP Code:
notice in the above INSERT statment that there is no single quote around the FROM_UNIXTIME() funtion. |
|
#11
|
|||
|
|||
|
Quote:
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 |
|
#12
|
|||
|
|||
|
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.
|
|
#13
|
|||
|
|||
|
Quote:
Ok i found the problem: Basicly because of my if/else loops i needed to reconnect to my database at the update portion. |
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > Storing time stamp |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|