質問編集履歴

1

javascriptのソースを追加しました。

2019/01/30 06:32

投稿

conchel1989
conchel1989

スコア13

test CHANGED
File without changes
test CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  "trip_id" : "";
10
10
 
11
- "sendSchedules" : {"0":{"startTime":[],"name":[],"requiredTime":[],"lat":[],"lng":[],"kind":[]},
11
+ "schedules" : {"0":{"startTime":[],"name":[],"requiredTime":[],"lat":[],"lng":[],"kind":[]},
12
12
 
13
13
  "1":{"startTime":[],"name":[],"requiredTime":[],"lat":[],"lng":[],"kind":[]},
14
14
 
@@ -38,6 +38,8 @@
38
38
 
39
39
 
40
40
 
41
+ try {
42
+
41
43
  $schedules = $_POST['schedules'];
42
44
 
43
45
  $trip_id = $_POST['trip_id'];
@@ -64,7 +66,7 @@
64
66
 
65
67
  $stmt->bindParam(':name',$count['name'], PDO::PARAM_STR);
66
68
 
67
- $stmt->bindValue(':time',intval(['requiredTime']), PDO::PARAM_INT);
69
+ $stmt->bindValue(':time',intval($count['requiredTime']), PDO::PARAM_INT);
68
70
 
69
71
  $stmt->bindParam(':lat',$count['lat'], PDO::PARAM_STR);
70
72
 
@@ -78,12 +80,88 @@
78
80
 
79
81
  $stmt->execute();
80
82
 
83
+
84
+
85
+ $stmt = null;
86
+
87
+ $dbh = null;
88
+
89
+
90
+
91
+ }catch (PDOExceaption $e) {
92
+
93
+ err_log($e->getMessage());
94
+
95
+ header('Content-Type: text/plain; charset=UTF-8', true, 500);
96
+
97
+ exit();
98
+
81
99
  }
82
100
 
101
+ }
102
+
83
103
 
84
104
 
85
105
  ```
86
106
 
107
+ ```javasctipt
108
+
109
+ function insertSchedules(){
110
+
111
+ "trip_id" : "";
112
+
113
+ "schedules" : {"0":{"startTime":[],"name":[],"requiredTime":[],"lat":[],"lng":[],"kind":[]},
114
+
115
+ "1":{"startTime":[],"name":[],"requiredTime":[],"lat":[],"lng":[],"kind":[]},
116
+
117
+ "2":{"startTime":[],"name":[],"requiredTime":[],"lat":[],"lng":[],"kind":[]}};
118
+
119
+
120
+
121
+ var sendSchedules = JSON.stringify(schedules);
122
+
123
+ var json = $.parseJSON(sendSchedules);
124
+
125
+
126
+
127
+ $.ajax({
128
+
129
+ type: "POST",
130
+
131
+ url: "insertSchedules.php",
132
+
133
+ datatype: "json",
134
+
135
+ data:{
136
+
137
+ 'schedules': json,
138
+
139
+ 'trip_id' : 1
140
+
141
+ },
142
+
143
+ }).done( (data) => {
144
+
145
+ console.log(data);
146
+
147
+ return data;
148
+
149
+ })
150
+
151
+ .fail( (data) => {
152
+
153
+ console.log(data);
154
+
155
+ })
156
+
157
+ .always( (data) => {
158
+
159
+ });
160
+
161
+ }
162
+
163
+ ```
164
+
87
165
 
88
166
 
89
167
  ### 試したこと
@@ -93,3 +171,133 @@
93
171
  dateTime型をバインドするところでエラーが出ていたので、その部分を直していたらエラーメッセージは消えたのですが、
94
172
 
95
173
  更新はされない状態になりました。
174
+
175
+ ご指摘にあったとおりにjson_decodeにデータを通してみたところ
176
+
177
+   $post_array = json_decode($schedules,true);
178
+
179
+
180
+
181
+ <b>Warning</b>: json_decode() expects parameter 1 to be string, array given in <b>/var/www/html/koba/plover/dao/insertSchedules.php</b> on line <b>53</b><br />
182
+
183
+
184
+
185
+ <b>Warning</b>: Invalid argument supplied for foreach() in <b>/var/www/html/koba/plover/dao/insertSchedules.php</b> on line <b>61</b><br />
186
+
187
+ が表示されてしまいました。
188
+
189
+
190
+
191
+ ```
192
+
193
+ var_dump($_POST);の結果は以下です。
194
+
195
+
196
+
197
+ array(2) {
198
+
199
+ ["schedules"]=>
200
+
201
+ array(3) {
202
+
203
+ [0]=>
204
+
205
+ array(6) {
206
+
207
+ ["startTime"]=>
208
+
209
+ string(19) "YYYY-mm-dd hh:mm:ss"
210
+
211
+ ["name"]=>
212
+
213
+ string(9) "***"
214
+
215
+ ["requiredTime"]=>
216
+
217
+ string(1) "0"
218
+
219
+ ["lat"]=>
220
+
221
+ string(9) "00.000000"
222
+
223
+ ["lng"]=>
224
+
225
+ string(9) "000.000000"
226
+
227
+ ["kind"]=>
228
+
229
+ string(4) "**"
230
+
231
+ }
232
+
233
+ [1]=>
234
+
235
+ array(6) {
236
+
237
+ ["startTime"]=>
238
+
239
+ string(19) "YYYY-mm-dd hh:mm:ss"
240
+
241
+ ["name"]=>
242
+
243
+ string(12) "****"
244
+
245
+ ["requiredTime"]=>
246
+
247
+ string(2) "60"
248
+
249
+ ["lat"]=>
250
+
251
+ string(9) "00.000000"
252
+
253
+ ["lng"]=>
254
+
255
+ string(10) "000.000000"
256
+
257
+ ["kind"]=>
258
+
259
+ string(0) ""
260
+
261
+ }
262
+
263
+ [2]=>
264
+
265
+ array(6) {
266
+
267
+ ["startTime"]=>
268
+
269
+ string(19) "YYYY-mm-dd hh:mm:ss"
270
+
271
+ ["name"]=>
272
+
273
+ string(13) "******"
274
+
275
+ ["requiredTime"]=>
276
+
277
+ string(2) "30"
278
+
279
+ ["lat"]=>
280
+
281
+ string(9) "00.000000"
282
+
283
+ ["lng"]=>
284
+
285
+ string(10) "000.000000"
286
+
287
+ ["kind"]=>
288
+
289
+ string(4) "****"
290
+
291
+ }
292
+
293
+ }
294
+
295
+ ["trip_id"]=>
296
+
297
+ string(1) "1"
298
+
299
+ }
300
+
301
+
302
+
303
+ ```