0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

PHPでDB操作していた時に起こった備忘録 SQLSTATE[42S22]:のエラー

Last updated at Posted at 2021-12-06

##環境
PHP
MySQL(Docker)
Vscode

##エラー

Column not found: 1054 Unknown column 'hoge hoge' in 'where clause'

##解決
なんてことはなく、SQLの文が悪かった。空白文字の検索などを調べていたが原因はもっと浅いところにあった。

if(isset($_POST["del_name"])){
  $del_name = $_POST["del_name"];
  $del_sql = "DELETE FROM table WHERE colum = '". $del_name ."'";
  $stmt = $PDO->prepare($del_sql);
  $stmt -> execute();

DELETE FROM table WHERE colum = 'hoge hoge'";

上記の文が本来動くものであったが、引用符がガバガバで間違えてた模様。

そもそもSQL文ができていなかったので勉強し直します。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?