質問編集履歴

3

修正

2018/10/18 12:55

投稿

takeke
takeke

スコア60

test CHANGED
File without changes
test CHANGED
@@ -28,7 +28,7 @@
28
28
 
29
29
  ```
30
30
 
31
- Fatal error: Uncaught PDOException: 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 '$last_s_id' at line 1 in C:\xampp\htdocs\scd\php\top.php:25 Stack trace: #0 C:\xampp\htdocs\scd\php\top.php(25): PDOStatement->execute(Array) #1 {main} thrown in C:\xampp\htdocs\scd\php\top.php on line 25
31
+ Fatal error: Uncaught Error: Call to undefined method PDOStatement::excute() in C:\xampp\htdocs\scd\php\top.php:29 Stack trace: #0 {main} thrown in C:\xampp\htdocs\scd\php\top.php on line 29
32
32
 
33
33
  ```
34
34
 
@@ -38,11 +38,13 @@
38
38
 
39
39
  $stmt = $pdo->prepare('INSERT INTO schedule(start_date,end_date,start_time,end_time,plan_category,plan_title,plan_detail,place,pab_flag) VALUES (?,?,?,?,?,?,?,?,?)');
40
40
 
41
+ $stmt->execute([$start_date, $end_date, $start_time, $end_time, $plan_category, $plan_title, $plan_detail, $place, $pab_flag]);
42
+
41
43
  $last_s_id = 'SELECT LAST_INSERT_ID()';
42
44
 
43
45
  $stmt = $pdo->prepare('INSERT INTO user_schedule(schedule_id) VALUES $last_s_id');
44
46
 
45
- $stmt->execute([$start_date, $end_date, $start_time, $end_time, $plan_category, $plan_title, $plan_detail, $place, $pab_flag]); //25行目
47
+ $stmt->excute();
46
48
 
47
49
 
48
50
 

2

補足

2018/10/18 12:55

投稿

takeke
takeke

スコア60

test CHANGED
File without changes
test CHANGED
@@ -24,4 +24,32 @@
24
24
 
25
25
 
26
26
 
27
+ ひとまず今現在のエラーです。
28
+
29
+ ```
30
+
31
+ Fatal error: Uncaught PDOException: 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 '$last_s_id' at line 1 in C:\xampp\htdocs\scd\php\top.php:25 Stack trace: #0 C:\xampp\htdocs\scd\php\top.php(25): PDOStatement->execute(Array) #1 {main} thrown in C:\xampp\htdocs\scd\php\top.php on line 25
32
+
33
+ ```
34
+
35
+ ```php
36
+
37
+ $pdo = db_connect();
38
+
39
+ $stmt = $pdo->prepare('INSERT INTO schedule(start_date,end_date,start_time,end_time,plan_category,plan_title,plan_detail,place,pab_flag) VALUES (?,?,?,?,?,?,?,?,?)');
40
+
41
+ $last_s_id = 'SELECT LAST_INSERT_ID()';
42
+
43
+ $stmt = $pdo->prepare('INSERT INTO user_schedule(schedule_id) VALUES $last_s_id');
44
+
45
+ $stmt->execute([$start_date, $end_date, $start_time, $end_time, $plan_category, $plan_title, $plan_detail, $place, $pab_flag]); //25行目
46
+
47
+
48
+
49
+ ```
50
+
51
+
52
+
53
+
54
+
27
55
  アドバイス等よろしくお願いいたします。

1

補足

2018/10/18 12:28

投稿

takeke
takeke

スコア60

test CHANGED
File without changes
test CHANGED
@@ -12,6 +12,14 @@
12
12
 
13
13
 
14
14
 
15
+ 登録の流れは、userが複数いて、scheduleを登録する際に、scheduleテーブルの項目と、そのスケジュールに参加するuserも一緒に登録する流れです。
16
+
17
+
18
+
19
+ scheduleテーブルにはカラムとしてuser関連のものは持っていないので、user_scheduleテーブルが1つのschedule_idと1つOR複数のuser_idを持ちます。
20
+
21
+
22
+
15
23
  やってみたことは、insertして、excuteしてからまたinsertみたいなことや、最初のinsertの時にjoinでuser_schedule,scheduleを結合くらいはしましたがやはりうまくいきませんでした。
16
24
 
17
25