<?php
$con=mysqli_connect("localhost","root","","admin");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$time=strftime('%c');
$sql="INSERT INTO bookreserve(libid,bookid,issuedate ,time)
VALUES
('$_POST[libid]','$_POST[bookid]','$_POST[issuedate]','$time')";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
echo "wait for conformation";
mysqli_close($con);
?>
当我看到我的bookreserve表时,值为时间栏中的00:00:00
答案 0 :(得分:1)
您为strftime()
选择了错误的修饰符,因为时间字段必须为HH:mm:ss格式。在这种情况下你想要:
$time=strftime('%H:%i:%s'); // date('H:i:s') would probably also suffice
或者您为数据库列选择了错误的数据类型。如果你真的想要%c格式的日期,你应该把它改成varchar。 (我认为varchar(23)
应该有效。)
您也可以更改查询以使用MySQL自己的功能:
$sql="INSERT INTO bookreserve(libid,bookid,issuedate ,time)
VALUES
('$_POST[libid]','$_POST[bookid]','$_POST[issuedate]',NOW())";