我正在尝试将我的表单中的数据插入到mysql中,这很好但是当我使用TimeStamp和CURRENT_TIMESTAMP添加'date_created'列时,会导致sql查询失败?
谁能告诉我为什么会这样?
这是我的mysql函数:
<?php ob_start();
// CONNECT TO THE DATABASE
require('../includes/_config/connection.php');
// LOAD FUNCTIONS
require('../includes/functions.php');
$username = $_POST['username'];
$password = $_POST['password'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$age = $_POST['age'];
$gender = $_POST['gender'];
$country = $_POST['country'];
$query="INSERT INTO ptb_registrations (ID,
username,
password,
firstname,
lastname,
email,
age,
gender,
country
)
VALUES('NULL',
'".$username."',
'".$password."',
'".$firstname."',
'".$lastname."',
'".$email."',
'".$age."',
'".$gender."',
'".$country."'
)";
mysql_query($query) or die ('Error updating database');
?>
<?php include ('send_email/reg_email.php'); ?>
<? ob_flush(); ?>
答案 0 :(得分:0)
您可以尝试将此日期/时间列添加到表格中。然后再次尝试插入查询,看看它是否有效:
ALTER TABLE table_name ADD timeanddate_colname TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;
答案 1 :(得分:0)
如果您的列不是时间戳,那么就像那样改变您的表
ALTER TABLE table_name ADD DEFAULT (CURRENT_TIMESTAMP) FOR [Cold2]
或者如果您可以CURDATE()
或NOW()