有邮政编码mysqli的麻烦

时间:2017-04-10 18:40:03

标签: mysqli

我卡住了,我的代码没有错误,但报告的语法错误 - 我尝试了很多东西,无法让记录更新。

已成功连接 - 错误 - 您的SQL语法出错;检查与您的MySQL服务器版本对应的手册,以便在''10',weight'4.00',price '69.0000'附近使用正确的语法,其中products_id ='29''在第3行

<?php error_reporting(E_ALL);
    ini_set('display_errors', '1');
    ?>
<?php
  include 'connect.php';
   if(isset($_POST['btn_submit'])){
      $sql ="update products set 

                        quantity'".$_POST['txt_quantity']."',
                        weight'".$_POST['txt_weight']."',
                        price'".$_POST['txt_price']."',
            where products_id = '".$_POST['txt_id']."'
    ";
    if(mysqli_query($con, $sql)){
        header('Location:index.php');   
    }else{
        echo "Error " .mysqli_error($con);
   }
}

if(isset($_GET['id'])){
     $sql = "SELECT products_id, products_quantity, products_weight, 
products_price 
            FROM products 
            where products_id=" .$_GET['id'];
$result = mysqli_query($con, $sql);
if(mysqli_num_rows($result)>0){
   ($row = mysqli_fetch_assoc($result)); 
 $id = $row['products_id'];
 $quantity = $row['products_quantity'];
 $weight = $row['products_weight'];
 $price = $row['products_price'];
     }
 }


 ?>

<form action="" method="post">
  <table>
    <tr>
      <td>Quantity</td>
      <td><input name = "txt_quantity" value ="<?=$quantity?>"></td>
    </tr>
    <tr>
      <td>Weight</td>
      <td><input name = "txt_weight" value ="<?=$weight?>"></td>
    </tr>
    <tr>
      <td>Price</td>
      <td><input name = "txt_price" value ="<?=$price?>"></td>
    </tr>
    <tr>
      <td><input type = "hidden" value ="<?=$id?>" name = "txt_id" ></td>
      <td><input type="submit" name="btn_submit"></td>
    </tr>
  </table>
</form>

我认为错误是在where子句的某个地方,查看并尝试更改以下许多示例我无法将其发布。数据检索正常但我无法编辑然后发布更新。

0 个答案:

没有答案