我正在使用MySQL Query在数据库中创建产品但我收到错误:
您的SQL语法有错误;检查与您的MySQL服务器版本对应的手册,以便在#des; fprice,inkoop,image,author,html附近使用正确的语法。值(' 1',' bronze 5 - 青铜4',' 1'在第1行
我用谷歌搜索了它,但在我的代码中找不到任何问题:
<?php
if(isset($_POST['submit'])) {
$shopid1 = $_POST['productid'];
$prodname1 = $_POST['productname'];
$desc1 = $_POST['desc'];
$fprice1 = $_POST['fprice'];
$price1 = $_POST['price'];
$inkoop1 = $_POST['inkoop'];
$image1 = $_POST['image'];
$qty1 = $_POST['qty'];
$html1 = $_POST['html'];
$author1 = $_SESSION['name'];
mysql_query("INSERT INTO products(shopid, name, qty, price, desc, fprice, inkoop, image, author, html) VALUES('$shopid1', '$prodname1', '$qty1', '$price1', '$desc1', '$fprice1', '$inkoop1', '$image1', '$author1', '$html1')", $conn)
or die(mysql_error());
Header("Location: products.php");
} else {
}
?>
希望有人可以诊断我的问题!谢谢!
答案 0 :(得分:1)
desc
是保留关键字。试试 -
INSERT INTO products(shopid, name, qty, price, `desc`,.....
或者相应地重命名。
答案 1 :(得分:0)
desc
是一个关键字,它可以使用反引号使用,也可以在数据库中重命名(如果可能)。请尝试以下方法:
INSERT INTO products
(shopid, name, qty, price, `desc`, fprice, inkoop, image, author, html)
VALUES
('$shopid1', '$prodname1', '$qty1', '$price1', '$desc1', '$fprice1', '$inkoop1', '$image1', '$author1', '$html1')
答案 2 :(得分:0)
尝试逃避查询中的keyword
(desc)
<?php
if(isset($_POST['submit'])) {
$shopid1 = $_POST['productid'];
$prodname1 = $_POST['productname'];
$desc1 = $_POST['desc'];
$fprice1 = $_POST['fprice'];
$price1 = $_POST['price'];
$inkoop1 = $_POST['inkoop'];
$image1 = $_POST['image'];
$qty1 = $_POST['qty'];
$html1 = $_POST['html'];
$author1 = $_SESSION['name'];
mysql_query("INSERT INTO products(shopid, name, qty, price, `desc`, fprice, inkoop, image, author, html) VALUES('$shopid1', '$prodname1', '$qty1', '$price1', '$desc1', '$fprice1', '$inkoop1', '$image1', '$author1', '$html1')", $conn)
or die(mysql_error());
Header("Location: products.php");
} else {
}
?>
您还可以查看保留的关键字,以便下次再犯错误MYSQL Reserved Keyword