回答編集履歴

3

修正

2015/10/24 14:55

投稿

退会済みユーザー
test CHANGED
@@ -152,7 +152,7 @@
152
152
 
153
153
  $room_id = $arrPost['room_id'];
154
154
 
155
- $arrEquipmentId = (isset($arrPost['equipment'])) ? $arrPost['equipment'] : null;
155
+ $arrEquipmentId = (isset($arrPost['equipment'])) ? $arrPost['equipment'] : [];
156
156
 
157
157
 
158
158
 

2

修正

2015/10/24 14:55

投稿

退会済みユーザー
test CHANGED
@@ -140,17 +140,19 @@
140
140
 
141
141
 
142
142
 
143
+ ```html
144
+
143
145
  <?php
144
146
 
145
- if (null != filter_input(INPUT_POST, 'equipment') &&
147
+ if (null != filter_input_array(INPUT_POST)) {
146
-
148
+
147
- 0 < filter_input(INPUT_POST, 'room_id')) {
149
+ $arrPost = filter_input_array(INPUT_POST);
148
-
149
-
150
-
150
+
151
+
152
+
151
- $room_id = filter_input(INPUT_POST, 'room_id');
153
+ $room_id = $arrPost['room_id'];
152
-
154
+
153
- $arrEquipmentId = filter_input(INPUT_POST, 'equipment');
155
+ $arrEquipmentId = (isset($arrPost['equipment'])) ? $arrPost['equipment'] : null;
154
156
 
155
157
 
156
158
 
@@ -214,4 +216,6 @@
214
216
 
215
217
  </html>
216
218
 
217
-
219
+ ```
220
+
221
+

1

追記

2015/10/24 14:47

投稿

退会済みユーザー
test CHANGED
@@ -129,3 +129,89 @@
129
129
  </form>
130
130
 
131
131
  ```
132
+
133
+
134
+
135
+ ---
136
+
137
+
138
+
139
+ 追記
140
+
141
+
142
+
143
+ <?php
144
+
145
+ if (null != filter_input(INPUT_POST, 'equipment') &&
146
+
147
+ 0 < filter_input(INPUT_POST, 'room_id')) {
148
+
149
+
150
+
151
+ $room_id = filter_input(INPUT_POST, 'room_id');
152
+
153
+ $arrEquipmentId = filter_input(INPUT_POST, 'equipment');
154
+
155
+
156
+
157
+ //$dbh =
158
+
159
+
160
+
161
+ foreach ($arrEquipmentId as $equipmentId) {
162
+
163
+ $vals = [];
164
+
165
+ $sql = 'INSERT INTO equipmet (id, room_id, euipment_id) VALUES (null, ?, ?)';
166
+
167
+ $vals[] = $room_id;
168
+
169
+ $vals[] = $equipmentId;
170
+
171
+
172
+
173
+ $stmt = $dbh->prepare($sql);
174
+
175
+ $stmt->execute($vals);
176
+
177
+ }
178
+
179
+ }
180
+
181
+ ?>
182
+
183
+ <!DOCTYPE HTML>
184
+
185
+ <html lang="en-US">
186
+
187
+ <head>
188
+
189
+ <meta charset="UTF-8">
190
+
191
+ <title></title>
192
+
193
+ </head>
194
+
195
+ <body>
196
+
197
+ <form action="" method="post">
198
+
199
+ <input type="hidden" name="room_id" value="1" />
200
+
201
+ <!-- master_euipment から動的に生成する -->
202
+
203
+ <label><input type="checkbox" name="equipment[]" value="1" />オートロック</label>
204
+
205
+ <label><input type="checkbox" name="equipment[]" value="2" />南向き</label>
206
+
207
+ <label><input type="checkbox" name="equipment[]" value="3" />インターネット</label>
208
+
209
+ <label><input type="checkbox" name="equipment[]" value="4" />対面キッチン</label>
210
+
211
+ </form>
212
+
213
+ </body>
214
+
215
+ </html>
216
+
217
+