查询失败!您的 SQL 语法有错误;检查与您的 MariaDB 服务器版本相对应的手册,在第 1 行的“order(product_id,customer_name,total_bill,quantity)VALUES(1,'taha khan',5368,22)”附近使用正确的语法
<?php
if ($_SERVER['REQUEST_METHOD'] == "POST") {
$product = $_POST['product_id'];
$customer_name = $_POST['customer'];
$qty = $_POST['qty'];
$product_cost = $_POST['product_cost'];
$total_bill = $product_cost * $qty;
$result = "INSERT INTO order(product_id,customer_name,total_bill,quantity)VALUES($product,'$customer_name',$total_bill,$qty)";
$query = query($result);
confirmQuery($query);
}
?>
Run Code Online (Sandbox Code Playgroud)
你不能命名你的表order并像那样使用它。那是一个保留关键字。
话虽如此,如果您坚持这样做,您仍然可以使用该名称:
INSERT INTO `order` (product_id...
Run Code Online (Sandbox Code Playgroud)
反引号将允许它工作。我的建议是命名您的表,orders以避免查询中的冲突。
我还需要注意的是,您的查询容易受到 SQL 注入攻击,这一点很重要。您永远不应该将原始输入直接放入您的数据库中。没有什么能阻止我在customer现场发布 SQL 查询的片段并窃取数据。
花点时间学习一下如何使用prepared statements,这将是非常有益的:https : //www.php.net/manual/en/mysqli.quickstart.prepared-statements.php
| 归档时间: |
|
| 查看次数: |
816 次 |
| 最近记录: |