質問編集履歴

3

画像の追加

2017/08/18 14:56

投稿

dog57
dog57

スコア131

test CHANGED
File without changes
test CHANGED
@@ -615,3 +615,5 @@
615
615
  ```
616
616
 
617
617
  ![イメージ説明](a36fb2e3d60cd360c807ca56e9a01a9e.png)![![イメージ説明](49c0be1064fdfaf16905695a085bead4.png)](4464fae1cc36a292a269e4562dcb56e9.png)
618
+
619
+ ![イメージ説明](d783b0823eb75aeae300e85ec58572bc.png)

2

画像の追加

2017/08/18 14:56

投稿

dog57
dog57

スコア131

test CHANGED
File without changes
test CHANGED
@@ -613,3 +613,5 @@
613
613
 
614
614
 
615
615
  ```
616
+
617
+ ![イメージ説明](a36fb2e3d60cd360c807ca56e9a01a9e.png)![![イメージ説明](49c0be1064fdfaf16905695a085bead4.png)](4464fae1cc36a292a269e4562dcb56e9.png)

1

HTMLソース\(入力フォーム\)、確認フォーム、mysqlに登録フォームを追加しました。

2017/08/18 14:55

投稿

dog57
dog57

スコア131

test CHANGED
File without changes
test CHANGED
@@ -16,4 +16,600 @@
16
16
 
17
17
 
18
18
 
19
+ 入力フォーム
20
+
21
+ ```html
22
+
23
+ <!DOCTYPE html>
24
+
25
+ <html lang=“ja”>
26
+
27
+ <head>
28
+
29
+ <meta charset="UTF-8">
30
+
31
+ <title>My Web Site</title>
32
+
33
+ <link rel="stylesheet" href="style2.css">
34
+
35
+
36
+
37
+ </head>
38
+
39
+ <body>
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+ <header>
48
+
49
+ <div class="header-left">
50
+
51
+ <img class="logo" src="https://www.fastpic.jp/images.php?file=3519571152.jpg" alt="ロゴ画像">
52
+
53
+ </div>
54
+
55
+
56
+
57
+ </header>
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+ <div class="main">
66
+
67
+ <ol class="topic-path">
68
+
69
+ <li><a href="#">一覧へ</a> > </li>
70
+
71
+ <li>登録</li>
72
+
73
+ </ol>
74
+
75
+
76
+
77
+
78
+
79
+ <div class="container">
80
+
81
+ <h1>登録</h1>
82
+
83
+ <hr>
84
+
85
+
86
+
87
+
88
+
89
+ <form action="confirm.php" method="post">
90
+
91
+ <table border="0" class="touroku">
92
+
93
+
94
+
95
+ <tr>
96
+
97
+ <td align="right"> 氏名: </td>
98
+
99
+ <td><input type="text" size="25" name="yourname"></td>
100
+
101
+ </tr>
102
+
103
+
104
+
105
+ <tr>
106
+
107
+ <td align="right"> 都道府県: </td>
108
+
109
+ <td> <select name="live">
110
+
111
+ <option value="選択してください">選択してください</option>
112
+
113
+ <option value="東京">東京</option>
114
+
115
+ <option value="大阪">大阪</option>
116
+
117
+ <option value="名古屋">名古屋</option>
118
+
119
+ </select>
120
+
121
+ </td>
122
+
123
+ </tr>
124
+
125
+
126
+
127
+ <tr>
128
+
129
+ <td align="right"> 電話番号: </td>
130
+
131
+ <td><input type="text" size="30" name="tel"></td>
132
+
133
+ </tr>
134
+
135
+
136
+
137
+ <tr>
138
+
139
+ <td align="right"> 性別: </td>
140
+
141
+ <td><label><input type="radio" name="gender" value="男性">男性</label>
142
+
143
+ <label><input type="radio" name="gender" value="女性">女性</label>
144
+
145
+ <label><input type="radio" name="gender" value="未回答">未回答</label>
146
+
147
+ </td>
148
+
149
+ </tr>
150
+
151
+
152
+
153
+ <tr>
154
+
155
+ <td align="right"> 趣味:</td>
156
+
157
+ <td>
158
+
159
+ <label><input type="checkbox" value="趣味" name="shumi[1]">映画</label>
160
+
161
+ <label><input type="checkbox" value="趣味" name="shumi[2]">グルメ</label>
162
+
163
+ <label><input type="checkbox" value="趣味" name="shumi[3]">スポーツ<br></label>
164
+
165
+ <label><input type="checkbox" value="趣味" name="shumi[4]">読書</label>
166
+
167
+ <label><input type="checkbox" value="趣味" name="shumi[5]">ファッション</label>
168
+
169
+ <label><input type="checkbox" value="趣味" name="shumi[6]">アニメ</label>
170
+
171
+ </td>
172
+
173
+ </tr>
174
+
175
+
176
+
177
+ <tr>
178
+
179
+ <td align="right"> 備考欄: </td>
180
+
181
+ <td><textarea name="kanso" rows="3" cols="40">感想</textarea></td>
182
+
183
+ </tr>
184
+
185
+
186
+
187
+ </table>
188
+
189
+
190
+
191
+ <a href="index.html"><input type="button" value="一覧へ戻る"></a>
192
+
193
+ <a href="confirm.php"><input type="submit" value="確認する"></a>
194
+
195
+ </form>
196
+
197
+
198
+
199
+
200
+
201
+ </div>
202
+
203
+ </div>
204
+
205
+ </div>
206
+
207
+
208
+
209
+ <footer>
210
+
211
+
212
+
213
+
214
+
215
+
216
+
217
+
218
+
219
+ </footer>
220
+
221
+
222
+
223
+ </div>
224
+
225
+
226
+
227
+ </body>
228
+
229
+ </html>
230
+
231
+
232
+
233
+ ```
234
+
235
+ 確認フォーム
236
+
237
+ ```php
238
+
239
+ <?php
240
+
241
+ // $_POSTで受け取る
242
+
243
+ $yourname = $_POST["yourname"];
244
+
245
+ $live = $_POST["live"];
246
+
247
+ $tel = $_POST["tel"];
248
+
249
+ $gender = $_POST["gender"];
250
+
251
+ $shumi = $_POST["shumi"];
252
+
253
+ $kanso = $_POST["kanso"];
254
+
255
+ ?>
256
+
257
+
258
+
259
+
260
+
261
+
262
+
263
+ <!DOCTYPE html>
264
+
265
+ <html>
266
+
267
+ <head>
268
+
269
+ <meta charset="utf-8" />
270
+
271
+ <title>My Web Site</title>
272
+
273
+ <link rel="stylesheet" href="style3.css">
274
+
275
+
276
+
277
+ </head>
278
+
279
+ <body>
280
+
281
+
282
+
283
+ <div class="main">
284
+
285
+ <div class="form-title"></div>
286
+
287
+ <h2>確認画面</h2>
288
+
289
+
290
+
291
+
292
+
293
+ <table border="0" class="form-item">
294
+
295
+ <tr>
296
+
297
+ <td align="right" class="form-item"> 氏名 : </td>
298
+
299
+ <td align="left"><?php echo $yourname ?></td>
300
+
301
+ </tr>
302
+
303
+
304
+
305
+ <tr>
306
+
19
- ![![イメージ説明](0fc56e270d6175c5436f56cd42dad2a8.png)](30f2bb08ff7cc266afecf054991daa54.png)
307
+ <td align="right" class="form-item"> 都道府県 : </td>
308
+
309
+ <td align="left"><?php echo $live ?></td>
310
+
311
+ </tr>
312
+
313
+
314
+
315
+ <tr>
316
+
317
+ <td align="right" class="form-item"> 電話番号 : </td>
318
+
319
+ <td align="left"><?php echo $tel ?></td>
320
+
321
+ </tr>
322
+
323
+
324
+
325
+ <tr>
326
+
327
+ <td align="right" class="form-item"> 性別 : </td>
328
+
329
+ <td align="left">
330
+
331
+ <?php
332
+
333
+ if (isset($_POST["gender"])) {//もしPOSTに[genderがあれば
334
+
335
+ if ($_POST["gender"] == "男性") { //もし男性なら
336
+
337
+ echo "男性";
338
+
339
+ }
340
+
341
+ elseif ($_POST["gender"] == "女性") { //女性なら
342
+
343
+ echo "女性";
344
+
345
+ }
346
+
347
+ elseif ($_POST["gender"] == "未回答") { //未回答なら
348
+
349
+ echo "未回答";
350
+
351
+ }
352
+
353
+ else {
354
+
355
+ echo "どれかチェックしてから[送信]ボタンを押してください。";
356
+
357
+ }
358
+
359
+ }
360
+
361
+ ?>
362
+
363
+ </td>
364
+
365
+ </tr>
366
+
367
+
368
+
369
+ <tr>
370
+
371
+ <td align="right" class="form-item"> 趣味 : </td>
372
+
373
+ <td align="left">
374
+
375
+ <?php
376
+
377
+ if (isset($_POST["shumi"])) { //チェックされていれば
378
+
379
+ $shumi = $_POST["shumi"]; //変数 $shumi に格納
380
+
381
+ }
382
+
383
+ if (isset($shumi[1])) {
384
+
385
+ echo " 映画";
386
+
387
+ }
388
+
389
+ if (isset($shumi[2])) {
390
+
391
+ echo " グルメ";
392
+
393
+ }
394
+
395
+ if (isset($shumi[3])) {
396
+
397
+ echo " スポーツ";
398
+
399
+ }
400
+
401
+ if (isset($shumi[4])) {
402
+
403
+ echo " 読書";
404
+
405
+ }
406
+
407
+ if (isset($shumi[5])) {
408
+
409
+ echo " ファッション";
410
+
411
+ }
412
+
413
+ if (isset($shumi[6])) {
414
+
415
+ echo " アニメ";
416
+
417
+ }
418
+
419
+ else {
420
+
421
+ echo "";
422
+
423
+ }
424
+
425
+ ?>
426
+
427
+ </td>
428
+
429
+ </tr>
430
+
431
+
432
+
433
+ <tr>
434
+
435
+ <td align="right" class="form-item"> 備考欄 : </td>
436
+
437
+ <td align="left"><?php echo $kanso ?></td>
438
+
439
+ </tr>
440
+
441
+ </table>
442
+
443
+
444
+
445
+ <form action="registration.php" method="post">
446
+
447
+ <input type="hidden" name="yourname" value="<?php echo $yourname; ?>">
448
+
449
+ <input type="hidden" name="live" value="<?php echo $live; ?>">
450
+
451
+ <input type="hidden" name="tel" value="<?php echo $tel; ?>">
452
+
453
+ <input type="hidden" name="gender" value="<?php echo $gender; ?>">
454
+
455
+ <input type="hidden" name="shumi" value="<?php echo $shumi; ?>">
456
+
457
+ <input type="hidden" name="kanso" value="<?php echo $kanso; ?>">
458
+
459
+ <a href="index2.html"><input type="button" name="back" width="30px" value="戻る"></a>
460
+
461
+ <a href="registratio.php"><input type="submit" name="button1" width="30px" value="送信"></p></a>
462
+
463
+ </form>
464
+
465
+
466
+
467
+ </div>
468
+
469
+ </div>
470
+
471
+
472
+
473
+
474
+
475
+ </body>
476
+
477
+ </html>
478
+
479
+
480
+
481
+ ```
482
+
483
+ 登録フォーム
484
+
485
+ ```php
486
+
487
+ <?php
488
+
489
+
490
+
491
+ require_once('index_db.php');
492
+
493
+
494
+
495
+
496
+
497
+ // $_POSTで受け取る
498
+
499
+ $yourname = $_POST["yourname"];
500
+
501
+ $live = $_POST["live"];
502
+
503
+ $tel = $_POST["tel"];
504
+
505
+ $gender = $_POST["gender"];
506
+
507
+ $shumi = $_POST["shumi"];
508
+
509
+ $kanso = $_POST["kanso"];
510
+
511
+
512
+
513
+
514
+
515
+ try {
516
+
517
+
518
+
519
+ //データーベースに接続
520
+
521
+ $yourname = $_POST['yourname'];
522
+
523
+ $live = $_POST['live'];
524
+
525
+ $tel = $_POST['tel'];
526
+
527
+ $gender = $_POST['gender'];
528
+
529
+ $shumi = $_POST['shumi'];
530
+
531
+ $kanso = $_POST['kanso'];
532
+
533
+
534
+
535
+ //ここに処理を記載
536
+
537
+ $stmt = $pdo->prepare("INSERT INTO member (yourname, live, tel, gender, shumi, kanso) VALUES (:yourname, :live, :tel, :gender, :shumi, :kanso)");
538
+
539
+ $stmt->bindValue(':yourname', $yourname, PDO::PARAM_STR);
540
+
541
+ $stmt->bindValue(':live', $live, PDO::PARAM_STR);
542
+
543
+ $stmt->bindValue(':tel', $tel, PDO::PARAM_STR);
544
+
545
+ $stmt->bindValue(':gender', $gender, PDO::PARAM_STR);
546
+
547
+ $stmt->bindValue(':shumi', $shumi, PDO::PARAM_STR);
548
+
549
+ $stmt->bindValue(':kanso', $kanso, PDO::PARAM_STR);
550
+
551
+ $stmt->execute();
552
+
553
+ var_dump($_POST['yourname']);
554
+
555
+ var_dump($_POST['live']);
556
+
557
+ var_dump($_POST['tel']);
558
+
559
+ var_dump($_POST['gender']);
560
+
561
+ var_dump($_POST['shumi']);
562
+
563
+ var_dump($_POST['kanso']);
564
+
565
+
566
+
567
+ //接続終了
568
+
569
+ $pdo = null;
570
+
571
+ }
572
+
573
+
574
+
575
+ //接続に失敗した際のエラー処理
576
+
577
+ catch (Exception $e){
578
+
579
+ echo 'error';
580
+
581
+ echo('エラーが発生しました。:'.$e->getMessage());
582
+
583
+ exit;
584
+
585
+ }
586
+
587
+
588
+
589
+
590
+
591
+ ?>
592
+
593
+ <html>
594
+
595
+ <head>
596
+
597
+
598
+
599
+ <title>OK</title>
600
+
601
+ </head>
602
+
603
+ <body>
604
+
605
+
606
+
607
+ <p>登録完了!</p>
608
+
609
+ </body>
610
+
611
+ </html>
612
+
613
+
614
+
615
+ ```