带有消息'SQLSTATE [42S22]的未捕获异常'PDOException':未找到列:1054 [重复]

带有消息'SQLSTATE [42S22]的未捕获异常'PDOException':未找到列:1054 [重复]

问题描述:

This question already has an answer here:

I tried to run the following code but it gets this error:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'ani123' in 'where clause'' in D:\xampp\htdocs\New folder\FINAL PROJECT\QQUIZ\admin\teacher\t_action.php:44 Stack trace: #0 D:\xampp\htdocs\New folder\FINAL PROJECT\QQUIZ\admin\teacher\t_action.php(44): PDO->exec('DELETE FROM `qu...') #1 {main} thrown in D:\xampp\htdocs\New folder\FINAL PROJECT\QQUIZ\admin\teacher\t_action.php on line 44

Here is my code:

$dltQuizesSql = "DELETE FROM `quizes` WHERE `username`=".$_GET['user']; // line 44
$stmt1 = $conn->exec($dltQuizesSql);

And here is an image of my table:

username exists in my table but I still get the error.

How can I solve it?

</div>

此问题已经存在 这里有一个答案: p>

  • 何时在MySQL中使用单引号,双引号和反引号 12 answers span> li> ul> div>

    我试图运行 以下代码,但它收到此错误: p>

    致命错误:未捕获异常'PDOException',消息'SQLSTATE [42S22]:未找到列:1054未知列'ani123' 在'where子句'中的D:\ xampp \ htdocs \新文件夹\ FINAL PROJECT \ QQUIZ \ admin \ teacher \ t_action.php:44堆栈跟踪:#0 D:\ xampp \ htdocs \ New folder \ FINAL PROJECT \ QQUIZ \ admin \ teacher \ t_action.php(44):PDO-&gt; exec('DELETE FROM`qu ...')#1 {m ain}抛出D:\ xampp \ htdocs \新文件夹\ FINAL PROJECT \ QQUIZ \ admin \ teacher \ t_action.php第44行 p> blockquote>

    这是我的代码 : p>

      $ dltQuizesSql =“DELETE FROM`quizes` WHERE`username` =”。$ _ GET ['user'];  //第44行
     $ stmt1 = $ conn-&gt; exec($ dltQuizesSql); 
      code>  pre> 
     
     

    这是我的表的图像: p>

    username code>存在于我的表格中,但我仍然 得到错误。 p>

    我该如何解决? p> div>

1) string should be enclosed by single quotes

 "DELETE FROM quizes WHERE username='".$_GET['user']."'"; 

2) Remove semicolon inside the brackets

( $stmt1 = $conn->exec($dltQuizesSql);)