我收到 SQL 错误,试图将表单插入数据库

I got an SQL error, trying to insert a form to the database

我不知道我做错了什么。我正在尝试向我的 table.

插入一个表格

Insert failed: (1064) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-v, youtube-c, portfolio-link, picture-link) VALUES('test', 'test', 'test@test.c' at line 1

<?php
ob_start();

$sub_firstname = trim($_POST["firstname"]);
$sub_lastname = trim($_POST["lastname"]);
$sub_email = trim($_POST["email"]);
$sub_youtube_v = trim($_POST["youtube-v"]);
$sub_youtube_c = trim($_POST["youtube-c"]);
$sub_channellink = trim($_POST["channel-link"]);
$sub_picturelink = trim($_POST["picture-link"]);

include('../dbconnect.php');

if (empty($sub_firstname) || empty($sub_lastname)) {
    header ("Location: ../panel.php?page=artikler.php&create=empty");
    exit;
}

$sub_firstname = $mysqli->real_escape_string($sub_firstname);
$sub_lastname = $mysqli->real_escape_string($sub_lastname);

if (!$mysqli->query("INSERT INTO submittedforms (firstname, lastname, email, youtube-v, youtube-c, portfolio-link, picture-link) VALUES('$sub_firstname', '$sub_lastname', '$sub_email', '$sub_youtube_v', '$sub_youtube_c', '$sub_channellink', '$sub_picturelink')")) {
 echo "Insert failed: (" . $mysqli->errno . ") " . $mysqli->error;
 die();
}else{
header("Location: ../panel.php?page=artikler.php&id=".$id."&create=success");
exit;
ob_flush();
}
?>

您的列标识符中不能有破折号 (-),除非您将其用刻度线括起来。否则它被视为减法运算符:

INSERT INTO submittedforms (firstname, lastname, email, `youtube-v`, `youtube-c`, `portfolio-link`, `picture-link`

最好不要在您的标识符中使用破折号。您应该改用下划线 (_)。