Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用当前时间戳时,将表单数据插入mysql失败?_Php_Html_Mysql - Fatal编程技术网

Php 使用当前时间戳时,将表单数据插入mysql失败?

Php 使用当前时间戳时,将表单数据插入mysql失败?,php,html,mysql,Php,Html,Mysql,我试图将表单中的数据插入mysql,这很好,但是当我添加一个带有时间戳和当前时间戳的“date\u created”列时,会导致sql查询失败吗 谁能告诉我这是为什么 以下是我的mysql函数: <?php ob_start(); // CONNECT TO THE DATABASE require('../includes/_config/connection.php'); // LOAD FUNCTIONS require('../includes/function

我试图将表单中的数据插入mysql,这很好,但是当我添加一个带有时间戳和当前时间戳的“date\u 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(); ?>

您可以尝试将日期/时间列添加到表中。然后再次尝试插入查询并查看其是否有效:

   ALTER TABLE table_name ADD timeanddate_colname TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;

如果您的列不是timestamp,那么像这样修改您的表

  ALTER TABLE table_name ADD DEFAULT (CURRENT_TIMESTAMP) FOR [Cold2]

或者还有其他情况,如果您可以通过
CURDATE()
NOW()

添加当前日期,您可以发布MySQL给您的错误吗?
MySQL\u error()
说明了什么?强制要求:必须使用
MySQL\u*
函数。不建议编写新代码,因为它将在将来被删除。相反,您创建的日期列是什么类型的?