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

質問編集履歴

1

新規登録フォームと確認フォームのコードを追加しました。

2017/08/18 06:18

投稿

dog57
dog57

スコア131

title CHANGED
File without changes
body CHANGED
@@ -17,6 +17,235 @@
17
17
  ```
18
18
 
19
19
  ###該当のソースコード
20
+
21
+ 新規登録フォーム
22
+ ```HTML
23
+ <!DOCTYPE html>
24
+ <html lang=“ja”>
25
+ <head>
26
+ <meta charset="UTF-8">
27
+ <title>My Web Site</title>
28
+ <link rel="stylesheet" href="style2.css">
29
+
30
+ </head>
31
+ <body>
32
+
33
+
34
+
35
+ <header>
36
+ <div class="header-left">
37
+ <img class="logo" src="https://www.fastpic.jp/images.php?file=3519571152.jpg" alt="ロゴ画像">
38
+ </div>
39
+
40
+ </header>
41
+
42
+
43
+
44
+ <div class="main">
45
+ <ol class="topic-path">
46
+ <li><a href="#">一覧へ</a> > </li>
47
+ <li>登録</li>
48
+ </ol>
49
+
50
+
51
+ <div class="container">
52
+ <h1>登録</h1>
53
+ <hr>
54
+
55
+
56
+ <form action="confirm.php" method="post">
57
+ <table border="0" class="touroku">
58
+
59
+ <tr>
60
+ <td align="right"> 氏名: </td>
61
+ <td><input type="text" size="25" name="yourname"></td>
62
+ </tr>
63
+
64
+ <tr>
65
+ <td align="right"> 都道府県: </td>
66
+ <td> <select name="live">
67
+ <option value="選択してください">選択してください</option>
68
+ <option value="東京">東京</option>
69
+ <option value="大阪">大阪</option>
70
+ <option value="名古屋">名古屋</option>
71
+ </select>
72
+ </td>
73
+ </tr>
74
+
75
+ <tr>
76
+ <td align="right"> 電話番号: </td>
77
+ <td><input type="text" size="30" name="tel"></td>
78
+ </tr>
79
+
80
+ <tr>
81
+ <td align="right"> 性別: </td>
82
+ <td><label><input type="radio" name="gender" value="男性">男性</label>
83
+ <label><input type="radio" name="gender" value="女性">女性</label>
84
+ <label><input type="radio" name="gender" value="未回答">未回答</label>
85
+ </td>
86
+ </tr>
87
+
88
+ <tr>
89
+ <td align="right"> 趣味:</td>
90
+ <td>
91
+ <label><input type="checkbox" value="趣味" name="shumi[1]">映画</label>
92
+ <label><input type="checkbox" value="趣味" name="shumi[2]">グルメ</label>
93
+ <label><input type="checkbox" value="趣味" name="shumi[3]">スポーツ<br></label>
94
+ <label><input type="checkbox" value="趣味" name="shumi[4]">読書</label>
95
+ <label><input type="checkbox" value="趣味" name="shumi[5]">ファッション</label>
96
+ <label><input type="checkbox" value="趣味" name="shumi[6]">アニメ</label>
97
+ </td>
98
+ </tr>
99
+
100
+ <tr>
101
+ <td align="right"> 備考欄: </td>
102
+ <td><textarea name="kanso" rows="3" cols="40">感想</textarea></td>
103
+ </tr>
104
+
105
+ </table>
106
+
107
+ <a href="index.html"><input type="button" value="一覧へ戻る"></a>
108
+ <a href="confirm.php"><input type="submit" value="確認する"></a>
109
+
110
+
111
+
112
+ </div>
113
+ </div>
114
+ </div>
115
+
116
+ <footer>
117
+
118
+
119
+
120
+
121
+ </footer>
122
+
123
+ </div>
124
+
125
+
126
+ </body>
127
+ </html>
128
+ ```
129
+
130
+ 確認フォーム
131
+ ```php
132
+ <?php
133
+ // $_POSTで受け取る
134
+ $yourname = $_POST["yourname"];
135
+ $live = $_POST["live"];
136
+ $tel = $_POST["tel"];
137
+ $gender = $_POST["gender"];
138
+ $shumi = $_POST["shumi"];
139
+ $kanso = $_POST["kanso"];
140
+ ?>
141
+
142
+
143
+
144
+ <!DOCTYPE html>
145
+ <html>
146
+ <head>
147
+ <meta charset="utf-8" />
148
+ <title>My Web Site</title>
149
+ <link rel="stylesheet" href="style3.css">
150
+
151
+ </head>
152
+ <body>
153
+
154
+ <div class="main">
155
+ <div class="form-title"></div>
156
+ <h2>確認画面</h2>
157
+
158
+
159
+ <table border="0" class="form-item">
160
+ <tr>
161
+ <td align="right" class="form-item"> 氏名 : </td>
162
+ <td align="left"><?php echo $yourname ?></td>
163
+ </tr>
164
+
165
+ <tr>
166
+ <td align="right" class="form-item"> 都道府県 : </td>
167
+ <td align="left"><?php echo $live ?></td>
168
+ </tr>
169
+
170
+ <tr>
171
+ <td align="right" class="form-item"> 電話番号 : </td>
172
+ <td align="left"><?php echo $tel ?></td>
173
+ </tr>
174
+
175
+ <tr>
176
+ <td align="right" class="form-item"> 性別 : </td>
177
+ <td align="left">
178
+ <?php
179
+ if (isset($_POST["gender"])) {//もしPOSTに[genderがあれば
180
+ if ($_POST["gender"] == "男性") { //もし男性なら
181
+ echo "男性";
182
+ }
183
+ elseif ($_POST["gender"] == "女性") { //女性なら
184
+ echo "女性";
185
+ }
186
+ elseif ($_POST["gender"] == "未回答") { //未回答なら
187
+ echo "未回答";
188
+ }
189
+ else {
190
+ echo "どれかチェックしてから[送信]ボタンを押してください。";
191
+ }
192
+ }
193
+ ?>
194
+ </td>
195
+ </tr>
196
+
197
+ <tr>
198
+ <td align="right" class="form-item"> 趣味 : </td>
199
+ <td align="left">
200
+ <?php
201
+ if (isset($_POST["shumi"])) { //チェックされていれば
202
+ $shumi = $_POST["shumi"]; //変数 $shumi に格納
203
+ }
204
+ if (isset($shumi[1])) {
205
+ echo " 映画";
206
+ }
207
+ if (isset($shumi[2])) {
208
+ echo " グルメ";
209
+ }
210
+ if (isset($shumi[3])) {
211
+ echo " スポーツ";
212
+ }
213
+ if (isset($shumi[4])) {
214
+ echo " 読書";
215
+ }
216
+ if (isset($shumi[5])) {
217
+ echo " ファッション";
218
+ }
219
+ if (isset($shumi[6])) {
220
+ echo " アニメ";
221
+ }
222
+ else {
223
+ echo "";
224
+ }
225
+ ?>
226
+ </td>
227
+ </tr>
228
+
229
+ <tr>
230
+ <td align="right" class="form-item"> 備考欄 : </td>
231
+ <td align="left"><?php echo $kanso ?></td>
232
+ </tr>
233
+ </table>
234
+
235
+
236
+ <a href="index2.html"><input type="button" name="back" width="30px" value="戻る"></a>
237
+ <a href="registration.php"><input type="submit" name="button1" width="30px" value="送信"></p></a>
238
+
239
+
240
+ </div>
241
+ </div>
242
+
243
+
244
+ </body>
245
+ </html>
246
+
247
+ ```
248
+
20
249
  ```PHP
21
250
  (index.php データーベースに繋げるための専用のファイル)
22
251