【发布时间】:2016-07-28 00:45:47
【问题描述】:
我已经阅读了许多有关当前时间戳的帖子,并尝试了提供的许多解决方案,但是没有一个解决了我的问题。我需要将当前时间戳添加到数据库中。我认为我的代码可能是其他解决方案不起作用的原因。其他一切都完美发布。时间戳只是给了我所有的“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_API,开始使用参数化查询。 -
阅读 CURRENT_TIMESTAMP dev.mysql.com/doc/refman/5.5/en/… - 另外,您还尝试将其作为字符串输入。