...

View Full Version : Display Date from MySQL in PHP form



Red_Rain
01-11-2012, 10:08 PM
All,
Im guessing this is going to be easy for any one to answer bc im such a ****ing noob but here goes. I have mysql fields set to DATETIME and i just want to pull out that data and have it display in my form. And i would also like to know how to insert a date into a mysql DATETIME field if you guys would be so kind as to assist. I really really would appreciate any help. Thanks guys

Adee
01-12-2012, 01:52 AM
for whatever type of form field you have, in the value field put <?php echo $dateTime; ?> where $dateTime is equal to whatever value u've pulled from the database.

Dubz
01-12-2012, 09:47 PM
Now I'm not positive on this, but from my previous experience on using the datetime format in the mysql db, it updates every time the row is updated. I'm not sure exactly because I never looked it up and I'm sure someone is going to come around and correct me on it but from what happened to me, every time I updated the row, the time updated of when it was updated.

Kekke
01-12-2012, 10:03 PM
You can get it such as:



$query = "select mydate from `dates` where id='1'";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result);

if(isset($row['mydate']) {
## Use $row['mydate'] and print the date wherever you want it, as a string
echo $row['mydate'];
}


To insert one, you can use the following (this depends on your localization though):



$query = "insert into `dates` (mydate) values (" . date("Y-m-d H:i:s") . ")";
mysql_query($query) or die (mysql_error());


For more information about date(), check this page:
http://php.net/manual/en/function.date.php

Red_Rain
01-12-2012, 10:55 PM
Kekke,
THANK YOU SO MUCH! Ive done tons of reading and you made the most sense to me. Thanks a million man.

TO everyone else who tried to help, thank you for your time. You guys are awesome



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum