我不知道我做错了什么。我正在尝试将表格插入我的桌子。
插入失败:(1064)您的SQL语法出错;检查与MySQL服务器版本对应的手册,以便在'-v,youtube-c,portfolio-link,picture-link'附近使用正确的语法VALUES('test','test','test@test.c'在第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();
}
?>
答案 0 :(得分:4)
您的列标识符中不能包含短划线(-
),除非您将它包装在刻度线中。否则它被视为减法运算符:
INSERT INTO submittedforms (firstname, lastname, email, `youtube-v`, `youtube-c`, `portfolio-link`, `picture-link`
最佳做法是不在标识符中使用短划线。您应该使用下划线(_
)代替。