繁体   English   中英

查询失败。 更新时您的 SQL 语法有错误

[英]Query failed. You have an error in your SQL syntax when updating

所以在一个学校项目上工作,我正在尝试创建一种方法来更新页面上的现有产品,只有我想要更新的价格和描述。 我就是想不通我哪里出错了。 提前致谢。

现在在update.php页面上,我创建了一个函数,以便它在选项、选择表单中动态显示产品。

这是错误,

查询失败您的 SQL 语法有错误; 检查与您的 MySQL 服务器版本相对应的手册,在第 1 行的“WHERE product = SAMSUNG 60" FULL HD QUAD CORE 3D SMART LCD LED TV ”附近使用正确的语法。

这是我的更新功能

函数更新数据(){

    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>
$query = "
UPDATE products 
   SET price = $itemprice
     , description = '$itemDescription'
 WHERE product = '$itemName'
";

现在看看准备好的和绑定的查询。 正如已经提到的,where 子句应该引用主键

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM