某些信息是通过PHP表单提交到此页面的,但是当我发布它时,我收到此错误...
Error: 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 '-code) VALUES ('','$title','$description','$post','$author','11th September 20' at line 1
任何人都知道这是为什么?
<?php
$description = addslashes($_POST[description]);
$post = addslashes($_POST[post]);
$title = addslashes($_POST[title]);
$date_posted = date("jS F Y");
$con=mysqli_connect("localhost","root","********","**********");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="INSERT INTO posts
(id, title, description,
post, author, date_posted,
category, image-code)
VALUES
('','$_POST[title]','$_POST[description]',
'$_POST[post]','$_POST[author]','$date_posted',
'$_POST[category]','$image')";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
echo "Draft Successfully Submitted!";
mysqli_close($con);
header("Location:queue.php");
?>
答案 0 :(得分:3)
如果你的列名中有破折号,你必须将它们包裹在刻度线中:
`image-code`
否则它看起来像减法运算符。
答案 1 :(得分:0)
上面的代码部分没有定义$ image,因此它将作为文字传递给MySQL。