Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为什么我的mySQL插件不工作?_Php_Mysql_Sql - Fatal编程技术网

Php 为什么我的mySQL插件不工作?

Php 为什么我的mySQL插件不工作?,php,mysql,sql,Php,Mysql,Sql,一些信息是通过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 Sep

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

如果要在列名中包含破折号,则必须将它们用记号括起来:

`image-code`

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

上面的代码部分没有定义$image,因此它将作为文本传递给MySQL

请,在您编写任何更多的SQL接口代码之前,您必须仔细阅读以避免严重的错误。使用
mysqli
时,您应该使用参数化查询,并将用户数据添加到查询中。切勿使用字符串插值来完成此操作。您不能一直忽略这个重要的建议。$image仍然在双引号中,因此如果有任何错误,$image将被计算为null。