note 56123 rejected from function.date by mazzanet
| From: | mazzanet@php.net | Date: | Wed, 24 Aug 2005 09:16:03 +0000 |
| Subject: | note 56123 rejected from function.date by mazzanet | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-94118@lists.php.net to get a copy of this message | ||
Note Submitter: a new php user
----
use php to get the current time and save it to the mysql database, then use php to read from the
database.
//////save_to_database.php//////
<?php
$date=time();
$date_display=date("d-F-Y", $date);
echo "display the current time before saving it to database:";
echo "<br>$data_display<br>";
$conn = mysql_connect("localhost","root","");
if (!$conn) die("mysql connection problem.");
mysql_select_db("databasename",$conn);
$sql = "insert into tablename (id, date) values (1, $date)";
$result = mysql_query($sql);
if (!$result) die("sql excute problem.");
echo "new entry inserted.";
mysql_close($conn);
?>
//////read_from_database.php//////
<?php
$conn = mysql_connect("localhost","root","");
if (!$conn) die("mysql connection problem.");
mysql_select_db("databasename",$conn);
$sql = "select * from tablename where id=1";
$result = mysql_query($sql);
if (!$result) die("sql excute problem.");
$content = mysql_result($result, 0, "date");
$content_display = date("d-F-Y",$content);
echo "The content is: $content_display";
mysql_close($conn);
?>
I've met a problem while saving the date to the database. The "display before saving"
bit goes well, and the sql has been excuted. A new entry has been inserted into the database.
BUT, the problem is that the new entry is always
"0000-00-00 00:00:00" instead of the current time.
So when I read from the database, it can only display the content as: 01-January-1970.
Is there anyone can help?