Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/228.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/61.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 - Fatal编程技术网

Php mySQL语法错误

Php mySQL语法错误,php,mysql,Php,Mysql,这个SQL查询出了什么问题 if(isset($_POST['submit'])){ $name = $_POST['name']; $author = $_POST['author']; $pub = $_POST['pub']; $sibn = $_POST['sibn']; $year = $_POST['year']; $version = $_POST['version']; $desc = $_POST['desc'];

这个SQL查询出了什么问题

if(isset($_POST['submit'])){
    $name = $_POST['name'];
    $author = $_POST['author'];
    $pub = $_POST['pub'];
    $sibn = $_POST['sibn'];
    $year = $_POST['year'];
    $version = $_POST['version'];
    $desc = $_POST['desc'];

    $selected_db = mysql_select_db("bookstore",$con);
    $query = "INSERT INTO introducebook (name, author, pub, sibn, year, version, desc) VALUES ('{$name}', '{$author}', '{$pub}', '{$sibn}', {$year}, {$version}, '{$desc}');" ;
    $result = mysql_query($query,$con);
    if(!$result){die('could not perform query'.mysql_error());}
    echo mysql_affected_rows();
}
?>
错误是(我通过了所有输入测试):

您的SQL语法有错误;请查看与MySQL服务器版本对应的手册,以了解在第1行使用“desc”值(“test”、“test”、“test”、“test”、“test”、test、test”)的正确语法

您需要像
desc
那样使用反勾号进行转义

INSERT INTO introducebook (name, ..., `desc`) VALUES ...

要传递纯文本,您需要括号,这是正确的

INSERT INTO introducebook (`name`, `author`, `pub`, `sibn`, `year`, `version`, `desc`) VALUES ('{$name}', '{$author}', '{$pub}', '{$sibn}', '{$year}', '{$version}', '{$desc}')
是的,你也需要反勾