我正在写一个网站,我有保存日期和时间到MySQL数据库使用PHP的问题,但我得到的日期是0000-00-00 00: 00:00。我不确定我的代码有什么问题,所以我希望你们能帮我指出一些问题。麻烦保存日期和时间到MySQL使用PHP
下面是INSERT功能我在一个外部php文件存储方便
<?php
class FITQuery {
public static function insert($table, $fields, $values, $condition = null) {
$query = "INSERT INTO ".$table;
$query .= '(';
for ($i = 0; $i < count($fields) - 1; $i++) {
$query .= $fields[$i].',';
}
$query .= $fields[count($fields) - 1];
$query .= ') VALUES (';
for ($i = 0; $i < count($values) - 1; $i++) {
$query .= "'".$values[$i]."',";
}
$query .= "'".$values[count($values) - 1]."'";
$query .= ') ';
if (mysql_query($query)) return true;
else die("INSERT:".mysql_error());
}
} ?>
这里是代码,我使用INSERT:
<?php
if (!empty($_POST)) {
// POST PROCESS
$title = $_POST['title'];
$short_desc = $_POST['short_desc'];
$content = $_POST['content'];
// FILE UPLOAD
if (isset($_FILES['avatar'])) {
$avatar = FITUtils::uploadFile($_FILES['avatar']['name'], $_FILES['avatar']['tmp_name'], "../uploads");
}
else $avatar = null;
// Insert
FITQuery::insert('news', array('title','short_desc','content','avatar','created_date'),
array($title, $short_desc, $content, $avatar, FITUtils::getDate()));
FITUtils::redirect('index.php?page=news');
}
else {
}
?>
我敢肯定它不是INSERT函数的问题,因为我已经尝试了“传统”方式,但仍然得到了相同的结果。任何人对我有一些建议?我是PHP新手,所以我希望你们可以帮助我。谢谢!
糟糕,比我想象的要简单。非常感谢! – 2011-12-17 04:21:49