[英]MySQL INSERT query does not update the DB
attent table : 参加表:
id int(11) primary key id int(11)主键
userID int (11) forigen key from users table userID int(11)来自users表的forigen键
date date 约会日期
start_time text start_time文本
end_time text end_time文本
approv enum default 0 approv enum默认值为0
my query : 我的查询:
$sql = "INSERT INTO attent ".
"(id,userID,date,start_time,end_time,approv) ".
"VALUES ".
"('NULL','$userid','$date','$start_time','$end_time','NULL')";
$query = mysqli_query($db,$sql);
I got config.php file that help communicate with dB. 我得到了config.php文件,有助于与dB通信。 I did a few insert queries before and all of them work just fine.
之前我做了一些插入查询,并且所有这些查询都运行得很好。 I can not understand where is my mistake.
我无法理解我的错误在哪里。
Try like this use back tick,because date is reserved word in mysql 尝试这样使用返回tick,因为date是mysql中的保留字
$sql = "INSERT INTO `attent` ".
"(`id`,`userID`,`date`,`start_time`,`end_time`,`approv`) ".
"VALUES ".
"('','$userid','$date','$start_time','$end_time','')";
Write your query as below:- 写下您的查询如下: -
"INSERT INTO attent(`id`,`userID`,`date`,`start_time`,`end_time`,`approv`)
VALUES(NULL,'$userid','$date','$start_time','$end_time',NULL)"
It's easier to understand what's going on if you will try to put such a query manually through eg phpMyAdmin 如果您尝试通过例如phpMyAdmin手动输入此类查询,则更容易理解发生了什么
I don't know your table structure but try to skip id
attribute as it's often autoincrementable. 我不知道你的表结构,但尝试跳过
id
属性,因为它通常是自动增量的。 You can always skip the fields that is not set to NOT NULL
. 您始终可以跳过未设置为
NOT NULL
的字段。
Like that: 像那样:
$sql = "INSERT INTO `attent` ".
"(`userID`,`date`,`start_time`,`end_time`,`approv`) ".
"VALUES ".
"('$userid','$date','$start_time','$end_time','')";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.