MySQL INSERT INTO 语句中的语法错误

我的代码有问题。每次尝试向数据库中插入内容时,都会出现语法错误。


这是我的数据库结构:


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


富国沪深
浏览 424回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP