所以在学校项目上工作,我正在尝试创建一种方法来更新页面上的现有产品,只有我想要更新的价格和描述。我无法解决我出错的地方。提前致谢。
现在在update.php
页面上,我创建了一个功能,以便在选项,选择表单中动态显示产品。
这是错误,
查询失败您的SQL语法中有错误;检查手册 对应于您的MySQL服务器版本,以获得正确的语法 在第1行的'WHERE product =
SAMSUNG 60" FULL HD QUAD CORE 3D SMART LCD LED TV
'附近使用。
这是我的更新功能
function updateData(){
if(isset($_POST['submit'])) {
global $db;
$itemName = $_POST['product'];
$itemprice = $_POST['itemPrice'];
$itemDescription = $_POST['itemDescription'];
$query = "UPDATE products SET ";
$query .= " price = `$itemprice`, ";
$query .= " description = `$itemDescription`, ";
$query .= " WHERE product = `$itemName` ";
$result = mysqli_query($db, $query);
if(!$result) {
die("query failed" . mysqli_error($db));
} else {
echo "Your details have been updated";
}
}
}
这是我的update.php页面
require_once ("Includes/simplecms-config.php");
require_once ("Includes/connectDB.php");
include("Includes/header.php");
include("functionsphp.php");
confirm_is_admin();
updateData();
// max file size for the html upload form
$max_file_size = 50 * 1024 * 1024; // size in bytes
// directory that will recieve the uploaded file
$dir = 'Images/products/';
?>
<div id="container">
<div id="admin">
<h1>update Product</h1>
<form id="product_form" class="dialogform"
action="editProduct.php" method="post" enctype="multipart/form-
data">
<div class="form_description">
<p>Fill in the details below to update details to the
catalog item.</p>
<select class="description" name="product" id="">
<?php ShowProduct();?>
</select>
</div>
<div id="container">
<div id="admin">
<h1>update Product</h1>
<form id="product_form" class="dialogform"
action="addProduct.php" method="post" enctype="multipart/form-
data">
<div class="form_description">
<p>Fill in the details below to update the product to
the catalog.</p>
</div>
<label class="description" for="itemPrice">Price</label>
<div>
<input id="itemPrice" name="itemPrice" type="text"
maxlength="255" />
</div>
<label class="description"
for="itemDescription">Description</label>
<div>
<textarea style="width: 350px; height: 108px;"
id="itemDescription" name="itemDescription"></textarea>
</div>
<input id="submit_button" class="button_text"
type="submit" name="submit" value="Submit" />
</form>
</div>
</div>
答案 0 :(得分:0)
$query = "
UPDATE products
SET price = $itemprice
, description = '$itemDescription'
WHERE product = '$itemName'
";
现在查看准备和绑定的查询。如前所述,where子句应引用主键