-1

一些信息是通过 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");
?>
4

2 回答 2

3

如果要在列名中包含破折号,则必须将它们包装在刻度中:

`image-code`

否则它看起来像减法运算符。

于 2013-09-11T21:21:41.810 回答
0

上面的代码部分没有定义 $image,所以它将作为文字传递给 MySQL。

于 2013-09-11T21:27:47.303 回答