【问题标题】:Why can't data update as it get submitted in from the form?为什么从表单提交的数据不能更新?
【发布时间】:2017-12-25 22:23:25
【问题描述】:

mysql 错误:此时无法更新数据,因为您的 SQL 语法有错误;检查与您的 MariaDB 服务器版本相对应的手册,以在第 1 行的 'INTO category SET title='Lenovo vibe p1m', description='Smartphone' where id=' 附近使用正确的语法

<html>
<head><title>form</title>
<link 
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" 
 rel="stylesheet"/>
<script
  src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
  integrity="sha256-k2WSCIexGzOj3Euiig+TlR8gA0EmPjuc79OEeY5L45g="
  crossorigin="anonymous"></script>
</head>
<body>
<h1><center>Items UPdate</center></h1>

<div class="container">
<form method="POST" action=" ">
<div class="form-group row">
  <label for="example-number-input" class="col-md-2 col-form-label">Id of 
 item</label>
  <div class="col-md-10">
    <input class="form-control" type="number" value="1" id="example-number-`input" name="id">`
  </div>
</div>

 <div class="form-group row">
 <label for="example-text-input" class="col-md-2 col-form-label">Item</label>
  <div class="col-md-10">
    <input class="form-control" type="text" value="Lenovo vibe p1m" id="example-text-input" name="item">
  </div>
  </div>

<div class="form-group row">
  <label for="example-search-input" class="col-md-2 col-form-label">Description</label>
  <div class="col-md-10">
    <input class="form-control" type="search" name="description" value="Smartphone" id="example-search-input">
  </div>
</div>

  <button type="submit" class="btn btn-primary">Submit</button>
</form>

<script src= "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

</form>
</div>

<?php 
print_r($_POST); 
$id = $_POST['id'];
$item = $_POST['item'];
$des = $_POST['description'];
include 'databaseConnect.php';

 $sql= "UPDATE INTO category SET title= '$item', description= '$des' where id= '$id'";
$query = mysqli_query($conn, $sql); 
if($query){
    echo "Data updated successfully";
  }else{
    echo "Data couldn't be updated at this moment because of " .mysqli_error($conn);
  }
?>
</body>
</html>

【问题讨论】:

    标签: php mysql database mysqli sql-update


    【解决方案1】:
    $sql= "UPDATE category SET title= '$item', description= '$des' where id= '$id'";
    

    更新时不需要INTO,保持sql这样

    【讨论】:

      【解决方案2】:

      对于更新,语法是

      UPDATE table_name 
      SET column1 = value1, column2 = value2, ...
      WHERE condition; 
      

      您的查询

      UPDATE INTO category SET title= '$item', description= '$des' where id= '$id'
      

      正确的查询

      UPDATE category SET title= '$item', description= '$des' where id= '$id'
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-10-04
        • 1970-01-01
        • 2019-03-08
        • 1970-01-01
        • 1970-01-01
        • 2015-05-15
        • 1970-01-01
        相关资源
        最近更新 更多