简体   繁体   English

获取记录创建日期MySql

[英]Getting Record Creation Date MySql

I have read several posts that relate to this question, but I still can not understand what I am doing wrong. 我已经阅读了与该问题有关的几篇文章,但我仍然无法理解我在做什么错。 For instance: 例如:

Saving timestamp in mysql table using php and Display the date of creation of a row in mysql 使用php将时间戳保存在mysql表中在mysql中 显示创建行的日期

All I want is to have the date a record is created put in a column of mysql database and then post it to a php results table. 我想要的是将创建记录的日期放在mysql数据库的列中,然后将其发布到php结果表中。

I have added a column to the database called 'Date' with Type:timestamp, Default:current_timestamp(), and Attributes:ON UPDATE CURRENT_TIMESTAMP(). 我在数据库中添加了名为“日期”的列,其类型为:时间戳,默认值:current_timestamp()和属性为:ON UPDATE CURRENT_TIMESTAMP()。 For some reason all rows in the 'Date' column show nothing but zeroes? 由于某种原因,“日期”列中的所有行都显示零。

How can I set up the column so it actually displays the creation date for each record? 如何设置该列,以便它实际显示每个记录的创建日期?

Here is a screenshot of my database structure: 这是我的数据库结构的屏幕截图: 在此处输入图片说明

And here is a screenshot of the database records: 这是数据库记录的屏幕截图:

在此处输入图片说明

Any help would be greatly appreciated. 任何帮助将不胜感激。

I figured it out! 我想到了! I was trying to insert the date via my insert.php script and it was finding a null value. 我试图通过我的insert.php脚本插入日期,但发现一个空值。 Once I removed the insertion of 'Date' it works as expected. 一旦删除“日期”的插入,它就会按预期工作。 Rookie mistake. 新秀错误。

Here is what the insert.php looked like prior to my edit: 这是我进行编辑之前insert.php的外观:

$sql = "INSERT INTO Medicard (Date, Name, Number, PartA, PartB, Full_Name, Address, Apt, City, State, Zip, Phone, Email) VALUES ('$_POST[Date]','$_POST[Name]','$_POST[Number]','$_POST[parta]','$_POST[partb]','$_POST[Full_Name]','$_POST[Address]','$_POST[Apt]','$_POST[City]','$_POST[State]','$_POST[Zip]','$_POST[Phone]','$_POST[Email]')";

I then removed the 'Date' insertion and it worked: 然后,我删除了'Date'插入,它起作用了:

$sql = "INSERT INTO Medicard (Name, Number, PartA, PartB, Full_Name, Address, Apt, City, State, Zip, Phone, Email) VALUES ('$_POST[Name]','$_POST[Number]','$_POST[parta]','$_POST[partb]','$_POST[Full_Name]','$_POST[Address]','$_POST[Apt]','$_POST[City]','$_POST[State]','$_POST[Zip]','$_POST[Phone]','$_POST[Email]')";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM