date
I'm trying to add a the date of submission into a Db...i use a SET for the other variables drawn from the form...here's what i tried, but it doesn't work...php.net was of no help:
<?php
$date = date(m-d-Y);
.....
.\", $date='$date'\"
?>
but it doesn't like that. how would i call the varible from the script to be inserted rather than the ones on the form?
nike_guy_man posted this at 00:39 — 13th November 2003.
They have: 840 posts
Joined: Sep 2000
What???
Can we see the whole script, or at least more of it??
<?php
$date = date(m-d-y);
$query = \"INSERT INTO table (info, date) VALUES ('\". $_POST[info] . \"', '\" . $date . \"')\";
?>
Right?
m3rajk posted this at 00:57 — 13th November 2003.
They have: 461 posts
Joined: Jul 2003
umm... doesn't date need the first argument in quotes (either double or single) and need a second argument?
and we need to know about your db. it's actually faster to use the db's date function if you can...
to be better able to answer you, could you answer the following questions?
1: what is your database
2: what date functions does it have?
2b: how is the feild set up?
2c: have you looked at what the db can do with it's date function to it to print the form you want?
most dbs should allow you to insert with "INSERT INTO yourtable (somefeild, anotherfeild, datefield) VALUES ('$somevalue', 'anothervalue', NOW())"
now, using MySQL, the NOW() function gives the date according to it's timezone in MM-DD-YYYY HH:MM:SS or something like that (not sure onthe exact)
to adjust it to a user's timezone, just call the feild as UNIX_TIMESTAMP(datefeild)
that gives it in gmt as a unix timestamp, which you can then format for display via: gmdate($timedisplaystyle, ($timefromdb+$gmtoffset));
hmmm... i may very well have given you enough information to get the answer once you answer those questions. hope i explained everything well enough
POSIX. because a stable os that doesn't have memory leaks and isn't buggy is always good.
kb posted this at 02:23 — 13th November 2003.
He has: 1,380 posts
Joined: Feb 2002
alright, well...i did a little test...i set $date=3 and then ran the php script with
<?php
.\",date=$date\"
?>
and it returned 3 in the MySQL db
but when i set $date= getdate(m-d-Y); it does nothing. my field shows up as blank in the db.
m3rajk...i tried what you said, none of it worked...
could this be a server problem since it doesn't display the time?
Suzanne posted this at 02:44 — 13th November 2003.
She has: 5,507 posts
Joined: Feb 2000
"3" is not a date.
druagord posted this at 04:02 — 13th November 2003.
He has: 335 posts
Joined: May 2003
getdate does work like this it will return a array contaning date info check this link to see how you can get values
http://www.php.net/manual/en/function.getdate.php
IF , ELSE , WHILE isn't that what life is all about
Busy posted this at 09:30 — 13th November 2003.
He has: 6,151 posts
Joined: May 2001
what is the data type of your 'data' database field?
it's not something like varchar(1) or anything is it?
kb posted this at 22:08 — 13th November 2003.
He has: 1,380 posts
Joined: Feb 2002
no, it was orginially date, then it was changed to varchar(10) for the $date=3 test, and now it's back to date
and druagord, i know that. i tried every different time function listed on php.net just to try and get one to work.
druagord posted this at 22:13 — 13th November 2003.
He has: 335 posts
Joined: May 2003
ok i'll show you how
<?php
$date = getdate();
$query = \"INSERT INTO table (info, date) VALUES ('\". $_POST[info] . \"', '\" . $date['mon'].\"-\".$date['mday'].\"-\".$date['year'] . \"')\";
?>
IF , ELSE , WHILE isn't that what life is all about
Mark Hensler posted this at 06:36 — 14th November 2003.
He has: 4,048 posts
Joined: Aug 2000
Eskater05, just change your date() line to:
$date = date("Y-m-d");
Mark Hensler posted this at 06:42 — 14th November 2003.
He has: 4,048 posts
Joined: Aug 2000
hehe.. ok, after reading through the thread. You've all got the concept, but have the wrong format for timestamps.
"year-month-day hours:minutes:seconds"
As far as I know, it's only we funny Americans who use the "month day year" format. Which to me, makes really no sence. Thats like "two hundred and four and thirty". The order has no relation to magnetude. Whereas "year month day" does.
Mark Hensler
If there is no answer on Google, then there is no question.
kb posted this at 04:04 — 15th November 2003.
He has: 1,380 posts
Joined: Feb 2002
awesome...I can't believe it took that long to figure out the order was wrong...lol
thanks mark.
m3rajk posted this at 03:50 — 17th November 2003.
They have: 461 posts
Joined: Jul 2003
the little things are often the hardest to see.
i would have answered sooner if i got back sooner.
it's moot now, but i would have pointed out you initially used date and were using getdate with what i had and told ya to check em both.
hint for next time, check similar functions on php.net.
POSIX. because a stable os that doesn't have memory leaks and isn't buggy is always good.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.