前提
題名のエラーにひっかかり、下記のサイトの通りsql文を変更しましたが、
Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near
のようなエラーが表示されうまくいきませんでした。
私が書いたsql文の中でどこがおかしいかわからないためMysqlにくわしいかた指摘していただきたいです。
https://poota.net/archives/786
https://nodoame.net/archives/8026
以下テーブル構造です
+----+---------+-------+------+
| id | is_done | title | pos |
+----+---------+-------+------+
| 19 | 0 | fg | 0 |
+----+---------+-------+------+
プリペアドステートメントをしていないことについては今回はおいておいてほしいです。
発生している問題・エラーメッセージ
You can't specify target table 'xxx' for update in FROM clause xxxはテーブル名
php
1 private function add() 2 { 3 $title = filter_input(INPUT_POST, 'title'); 4 $stmt = $this->pdo->prepare("INSERT INTO todos (title) VALUES (:title)"); 5 $stmt->bindValue('title', $title); 6 $stmt->execute(); 7 } 8 9 private function addPos() 10 { 11 $title = filter_input(INPUT_POST, 'title'); 12 13 $this->pdo->query("UPDATE todos SET pos = ((SELECT id FROM (SELECT id FROM todos WHERE title = '$title') AS tmp) + 100 WHERE title = '$title'"); 14 15// todoリストにおいてタスクのタイトルをデータベースに保存するメソッドです。 16 17// addPosはposの値にid + 100で設定しています。 18 19 }
補足情報(FW/ツールのバージョンなど)
windows 11
docker で開発環境を構築しています。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/09/07 00:37