teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

文字ミスです。

2021/08/14 09:28

投稿

GPE46232209
GPE46232209

スコア14

title CHANGED
@@ -1,1 +1,1 @@
1
- PHP SQL文章DELITEうまくいかない
1
+ PHP SQL文章DELETEうまくいかない
body CHANGED
File without changes

1

全体的に足りていたいところを足しました。

2021/08/14 09:28

投稿

GPE46232209
GPE46232209

スコア14

title CHANGED
File without changes
body CHANGED
@@ -1,20 +1,20 @@
1
1
  ### 前提・実現したいこと
2
- フォームで送られた2つのpostを条件にして2つのテーブルのカラムを削除するためにIDと時間が同時に合えば削除できるというものを作ろうとしています。時間条件がうまく入らず。DELETEがうまくいかない状態です。
2
+ フォームで送られた2つのpostを条件にして2つのテーブル(troubleテーブル、trouble_picテーブル)のカラムを削除するためにIDと時間が同時に合えば削除できるというものを作ろうとしています。時間条件がうまく入らず。DELETEがうまくいかない状態です。
3
3
 
4
4
 
5
5
  ### 発生している問題・エラーメッセージ
6
6
 
7
7
  ```
8
- SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ' b.send_time = '2021-08-13 19:43:39'' at line 1
8
+ SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ' trouble.send_time = '2021-08-13 19:43:39'' at line 1
9
9
  ```
10
10
 
11
11
  ### 該当のソースコード
12
12
 
13
- ```PHP
13
+ ```
14
14
  $ID = $_POST['ID'];
15
15
  $send_time =$_POST['send_time'];
16
16
 
17
- $delite = $db->prepare('DELETE a FROM trouble a JOIN trouble_pic b ON a.ID = b.ID AND a.send_time = b.send_time WHERE b.ID= :ID, b.send_time = :send_time ');
17
+ $delite = $db->prepare('DELETE trouble , trouble_pic FROM trouble LEFT JOIN trouble_pic ON trouble.ID = trouble_pic.ID AND trouble.send_time = trouble_pic.send_time WHERE trouble.ID = :ID, trouble.send_time = :send_time ');
18
18
  $delite ->bindParam(':ID', $ID, PDO::PARAM_STR);
19
19
  $delite->bindParam(':send_time', $send_time);
20
20
  $delite->execute();