PHP 检查会话是否有特权
PHP Check Session if one has privilege
我正在处理 MySQL 查询以在数据库中创建产品,但出现错误:
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 'desc, fprice, inkoop, image, author, html) VALUES('1', 'bronze 5 - bronze 4', '1' at line 1
我用 Google 搜索了它,但在我的代码中找不到任何问题:
<?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 {
}
?>
希望有人能诊断我的问题!谢谢!
desc
是保留关键字。试试 -
INSERT INTO products(shopid, name, qty, price, `desc`,.....
或相应地重命名。
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')
尝试在查询中转义 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
我正在处理 MySQL 查询以在数据库中创建产品,但出现错误:
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 'desc, fprice, inkoop, image, author, html) VALUES('1', 'bronze 5 - bronze 4', '1' at line 1
我用 Google 搜索了它,但在我的代码中找不到任何问题:
<?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 {
}
?>
希望有人能诊断我的问题!谢谢!
desc
是保留关键字。试试 -
INSERT INTO products(shopid, name, qty, price, `desc`,.....
或相应地重命名。
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')
尝试在查询中转义 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