sql语法错误* FROM'用户' WHERE id = 10'在第1行

时间:2017-01-28 06:18:08

标签: php mysql

好的,所以创建了一个从数据库中提取用户id的小表单,我还创建了一个函数。我收到以下错误。似乎无法弄清楚我做错了什么。提前致谢。

这是错误:

  

无法删除您在SQL语法中出错;检查手册   对应于您的MySQL服务器版本,以获得正确的语法   在' * FROM'用户附近使用' WHERE id = 12'在第1行

这是我的功能

 function  deleteUser(){
    global  $db;

    $id =  $_POST['id'];

  $query  = "DELETE * FROM 'users' ";
  $query  .="WHERE id = $id ";   
  $result =  mysqli_query($db, $query);

  if (!$result) {

      die ("could not delete" . mysqli_error($db));

  }   else {

      echo " user has been deleted";

     }   

}

这是表格

   <?php                

            require_once ("Includes/simplecms-config.php");
            require_once ("Includes/connectDB.php");
            include ("Includes/header.php");
            include ("functionsphp.php");

        if(isset($_POST['submit'])){

       deleteUser();

     }
     ?>

  <h1> Delete user details</h1>

  <form action="deleteUsers.php" method="post">

  <select name="id">

   <?php Showid() ?>

 </select>
 <p>Select the Id of the user to delete.</p>
 <br>

 <input type="submit" name="submit" value="DELETE">    

3 个答案:

答案 0 :(得分:1)

从查询中删除*

delete from user where id = $id

足够了,您的查询应该是这样的

$query  = "
  DELETE 
    FROM users
   WHERE id = $id
 ";

答案 1 :(得分:1)

SYNTAX是(删除*)

delete from `users` where `id` = '$id';

delete from users where id = '$id';
  1. QUOTES用于字符串值。
  2. BACKTICKS用于标识符名称。
  3. 仅当我们使用保留字作为标识符名称时,才需要

    BACKTICKS(`)。

    实施例

    123123e34是一个有效的标识符名称,但也是指数编号(我们需要在此处进行反引号)。

答案 2 :(得分:0)

无法在评论中显示。

尝试更改:

DELETE * FROM 'users'
-------^------^-----^--- Change these single quotes to backticks

DELETE FROM `users`