我已經閱讀了許多關於當前時間戳的帖子,並嘗試了很多提供的解決方案,但是他們沒有解決我的問題。我需要將當前時間戳添加到數據庫中。我認爲我的代碼可能是其他解決方案無法正常工作的原因。其他一切都完美髮布。時間戳記給我所有的「0」,我嘗試的其他解決方案給了我一個「第6行錯誤」。當前時間戳
這裏是我當前的代碼
<?php
$con = mysql_connect("mysql","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
/* Prevent duplicate submissions */
if (isset($_COOKIE['FormSubmitted']))
{
show_error('You may only submit this form once per session!');
}
mysql_select_db("seller", $con);
$sql="INSERT INTO listing (name, email, website, url, dropdown, price, date, visitors, income, host, description)
VALUES
('$_POST[name]', '$_POST[email]', '$_POST[website]', '$_POST[url]', '$_POST [dropdown]', '$_POST[price]', '$_POST[date]','$_POST[visitors]', '$_POST[income]', '$_POST[host]', '$_POST[description]', 'CURRENT_TIMESTAMP[subdate]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "Thank you for listing with us. <a href="#">Explore Now</a>";
mysql_close($con)
?>
對於'$ DEITY'的愛,這是2016年**停止使用'mysql_' APIS,並開始使用參數化查詢**。 –
閱讀CURRENT_TIMESTAMP https://dev.mysql.com/doc/refman/5.5/zh-cn/date-and-time-functions.html#function_current-timestamp - 另外,您還嘗試以字符串形式輸入。 –
可能重複[MySQL - insert current date/time?](http://stackoverflow.com/questions/19246309/mysql-insert-current-date-time) –