为了账号安全,请及时绑定邮箱和手机立即绑定

MySQL INSERT INTO 语句中的语法错误

MySQL INSERT INTO 语句中的语法错误

PHP
富国沪深 2021-06-29 13:57:08
我的代码有问题。每次尝试向数据库中插入内容时,都会出现语法错误。这是我的数据库结构:CREATE TABLE `notes` (  `id` int(12) NOT NULL,  `type` varchar(15) NOT NULL,  `title` varchar(43) NOT NULL,  `text` varchar(43) NOT NULL,  `group` varchar(32) NOT NULL,  `uid` int(64) NOT NULL,  `creator` int(64) NOT NULL,  `insert_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;ALTER TABLE `notes`  ADD PRIMARY KEY (`id`);ALTER TABLE `notes`  MODIFY `id` int(12) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=79;这就是我的代码<?php    session_start();    require '../config.php';    $notetype    = $_POST['type'];    $notetitle   = $_POST['title'];    $notetext    = $_POST['text'];    $notegroup   = $_POST['group'];    $noteuid     = $_POST['uid'];    $notecreator = $_POST['creator'];    $notetbname  = $note['tbname'];    $conn = new mysqli($databaseconfig['ip'], $databaseconfig['user'], $databaseconfig['pass'], $databaseconfig['dbname']);    if ($conn->connect_error) {        die("Connection failed: " . $conn->connect_error);    }    $sql = "INSERT INTO $notetbname (type, title, text, group, uid, creator)    VALUES ('$notetype', '$notetitle', '$notetext', '$notegroup', $noteuid, $notecreator);";    if ($conn->query($sql) === TRUE) {        echo "New record created successfully";    } else {        echo "Error: " . $sql . "<br>" . $conn->error;    }    $conn->close();?>这是我收到的错误消息:Error: INSERT INTO notes (type, title, text, group, uid, creator) VALUES ('player', 'Hello there', 'Good morning everybody', 'Cop', 3325, 103);You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'group, uid, creator) VALUES ('player', 'Hello there', 'Good morning everybody'' at line 1
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 423 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信