質問編集履歴

4

check_step5_1.phpをcheck_step5_2.phpに変更、<div><a href="index_step5_2.php?action=rewrite">&laquo;&nbsp;

2020/01/01 03:31

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -374,7 +374,7 @@
374
374
 
375
375
  ```php
376
376
 
377
- //check_step5_1.php
377
+ //check_step5_1.php -->check_step5_2.phpに変更
378
378
 
379
379
 
380
380
 
@@ -474,7 +474,7 @@
474
474
 
475
475
  </dl>
476
476
 
477
- <div><a href="index.php?action=rewrite">&laquo;&nbsp;書き直す</a> | <input type="submit" value="登録する" /></div>
477
+ <div><a href="index_step5_2.php?action=rewrite">&laquo;&nbsp;書き直す</a> | <input type="submit" value="登録する" /></div>
478
478
 
479
479
  </form>
480
480
 

3

コード修正、「// 書き直し」

2020/01/01 03:31

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -74,133 +74,329 @@
74
74
 
75
75
 
76
76
 
77
- $input_action = filter_input(INPUT_POST, 'action');
77
+ if (!empty($_POST)) {
78
78
 
79
79
 
80
80
 
81
+ // エラー項目の確認
82
+
83
+ if ($_POST['name'] == '') {
84
+
85
+ $error['name'] = 'blank';
86
+
87
+ }
88
+
89
+ if ($_POST['email'] == '') {
90
+
91
+ $error['email'] = 'blank';
92
+
93
+ }
94
+
95
+ if (strlen($_POST['password']) < 4) {
96
+
97
+ $error['password'] = 'length';
98
+
99
+ }
100
+
101
+ if ($_POST['password'] == '') {
102
+
103
+ $error['password'] = 'blank';
104
+
105
+ }
106
+
107
+
108
+
109
+ $fileName = $_FILES['image']['name'];
110
+
111
+
112
+
113
+ if (!empty($fileName)) {
114
+
115
+
116
+
117
+ $ext = substr($fileName, -3);
118
+
119
+
120
+
121
+ if ($ext != 'jpg' && $ext != 'gif') {
122
+
123
+ $error['image'] = 'type';
124
+
125
+ }
126
+
127
+ }
128
+
129
+
130
+
131
+ // 重複アカウントのチェック
132
+
81
- if (!empty($_POST)) {
133
+ if (empty($error)) {
134
+
135
+ $sql = sprintf('SELECT COUNT(*) AS cnt FROM members WHERE email="%s"',
136
+
137
+ mysqli_real_escape_string($db, $input_email)
138
+
139
+ );
140
+
141
+ $record = mysqli_query($db, $sql) or die(mysqli_error($db));
142
+
143
+
144
+
145
+ $table = mysqli_fetch_assoc($record);
146
+
147
+
148
+
149
+ if ($table['cnt'] > 0) {
150
+
151
+ $error['email'] = 'duplicate';
152
+
153
+ }
154
+
155
+ }
156
+
157
+
158
+
159
+ if (empty($error)) {
82
160
 
83
161
 
84
162
 
85
- // エラ項目の確認
86
-
87
- if ($_POST['name'] == '') {
88
-
89
- $error['name'] = 'blank';
90
-
91
- }
92
-
93
- if ($_POST['email'] == '') {
94
-
95
- $error['email'] = 'blank';
96
-
97
- }
98
-
99
- if (strlen($_POST['password']) < 4) {
100
-
101
- $error['password'] = 'length';
102
-
103
- }
104
-
105
- if ($_POST['password'] == '') {
106
-
107
- $error['password'] = 'blank';
108
-
109
- }
110
-
111
-
112
-
113
- $fileName = $_FILES['image']['name'];
114
-
115
-
116
-
117
- if (!empty($fileName)) {
163
+ // 画像をアップロドする 
164
+
165
+ $image = date('YmdHis') . $_FILES['image']['name'];
166
+
167
+
168
+
169
+ move_uploaded_file($_FILES['image']['tmp_name'], '../member_picture/' . $image);
170
+
171
+
172
+
173
+ $_SESSION['join'] = $_POST;
174
+
175
+
176
+
177
+ $_SESSION['join']['image'] = $image;
178
+
179
+
180
+
181
+ header('Location: check_step5_1.php');
182
+
183
+ exit();
184
+
185
+ }
186
+
187
+ }
188
+
189
+
190
+
191
+ // 書き直し
192
+
193
+ // 書き直し
194
+
195
+ if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'rewrite'){
196
+
197
+ $_POST = $_SESSION['join'];
198
+
199
+ $error['rewrite'] = true;
200
+
201
+ }
202
+
203
+ ?>
204
+
205
+
206
+
207
+ <!DOCTYPE>
208
+
209
+ <html>
210
+
211
+ <head>
212
+
213
+ <meta charset="UTF-8" />
214
+
215
+ <link rel="stylesheet" type="text/css" href="../style.css" />
216
+
217
+ <title>会員登録</title>
218
+
219
+ </head>
220
+
221
+
222
+
223
+ <body>
224
+
225
+ <div id="wrap">
226
+
227
+ <div id="head">
228
+
229
+ <h1>会員登録</h1>
230
+
231
+ </div>
232
+
233
+
234
+
235
+ <div id="content">
236
+
237
+
238
+
239
+ <p>次のフォームに必要事項をご記入ください。</p>
240
+
241
+
242
+
243
+ <form action="" method="post" enctype="multipart/form-data">
244
+
245
+ <dl>
246
+
247
+ <dt>ニックネーム<span class="required">必須</span></dt>
248
+
249
+ <dd>
250
+
251
+ <input type="text" name="name" size="35" maxlength="255"
252
+
253
+ value="<?php echo htmlspecialchars($input_name,
254
+
255
+ ENT_QUOTES, 'UTF-8'); ?>" />
256
+
257
+ <?php if ($input_name == 'blank'): ?>
258
+
259
+ <p class="error">* ニックネームを入力してください</p>
260
+
261
+ <?php endif; ?>
262
+
263
+ </dd>
264
+
265
+
266
+
267
+ <dt>メールアドレス<span class="required">必須</span></dt>
268
+
269
+ <dd>
270
+
271
+ <input type="text" name="email" size="35" maxlength="255"
272
+
273
+ value="<?php echo htmlspecialchars($input_email,
274
+
275
+ ENT_QUOTES, 'UTF-8'); ?>" />
276
+
277
+ <?php if ($input_email == 'blank'): ?>
278
+
279
+ <p class="error">* メールアドレスを入力してください</p>
280
+
281
+ <?php endif; ?>
282
+
283
+
284
+
285
+ <?php if ($input_email == 'duplicate'): ?>
286
+
287
+ <p class="error">* 指定されたメールアドレスはすでに登録されています</p>
288
+
289
+ <?php endif; ?>
290
+
291
+ </dd>
292
+
293
+
294
+
295
+ <dt>パスワード<span class="required">必須</span></dt>
296
+
297
+ <dd>
298
+
299
+ <input type="password" name="password" size="10" maxlength="20"
300
+
301
+ value="<?php echo htmlspecialchars($input_password,
302
+
303
+ ENT_QUOTES, 'UTF-8'); ?>" />
304
+
305
+ <?php if ($input_password == 'blank'): ?>
306
+
307
+ <p class="error">* パスワードを入力してください</p>
308
+
309
+ <?php endif; ?>
118
310
 
119
311
 
120
312
 
313
+ <?php if ($input_password == 'length'): ?>
314
+
315
+ <p class="error">* パスワードは4文字以上で入力してください</p>
316
+
317
+ <?php endif; ?>
318
+
319
+ </dd>
320
+
321
+
322
+
121
- $ext = substr($fileName, -3);
323
+ <dt>写真など</dt>
324
+
325
+ <dd>
326
+
327
+ <input type="file" name="image" size="35" value="test" />
328
+
329
+
330
+
331
+ <?php if ($input_image == 'type'):?>
332
+
333
+ <p class="error">* 写真などは「.gif」または「.jpg」の画像を指定してください</p>
334
+
335
+ <?php endif; ?>
122
336
 
123
337
 
124
338
 
125
- if ($ext != 'jpg' && $ext != 'gif') {
126
-
127
- $error['image'] = 'type';
128
-
129
- }
130
-
131
- }
132
-
133
-
134
-
135
- // 重複アカウントのチェック
136
-
137
- if (empty($error)) {
138
-
139
- $sql = sprintf('SELECT COUNT(*) AS cnt FROM members WHERE email="%s"',
140
-
141
- mysqli_real_escape_string($db, $input_email)
142
-
143
- );
144
-
145
- $record = mysqli_query($db, $sql) or die(mysqli_error($db));
146
-
147
-
148
-
149
- $table = mysqli_fetch_assoc($record);
150
-
151
-
152
-
153
- if ($table['cnt'] > 0) {
154
-
155
- $error['email'] = 'duplicate';
156
-
157
- }
158
-
159
- }
160
-
161
-
162
-
163
- if (empty($error)) {
164
-
165
-
166
-
167
- // 画像をアップロードする 
168
-
169
- $image = date('YmdHis') . $_FILES['image']['name'];
170
-
171
-
172
-
173
- move_uploaded_file($_FILES['image']['tmp_name'], '../member_picture/' . $image);
174
-
175
-
176
-
177
- $_SESSION['join'] = $_POST;
178
-
179
-
180
-
181
- $_SESSION['join']['image'] = $image;
182
-
183
-
184
-
185
- header('Location: check_step5_1.php');
186
-
187
- exit();
188
-
189
- }
190
-
191
- }
192
-
193
-
194
-
195
- // 書き直し
196
-
197
- if ($input_action == 'rewrite') {
198
-
199
- $_POST = $_SESSION['join'];
200
-
201
- $error['rewrite'] = true;
202
-
203
- }
339
+ <?php if (!empty($error)): ?>
340
+
341
+ <p class="error">* 恐れ入りますが、画像を改めて指定してください</p>
342
+
343
+ <?php endif; ?>
344
+
345
+ </dd>
346
+
347
+ </dl>
348
+
349
+ <div><input type="submit" value="入力内容を確認する" /></div>
350
+
351
+ </form>
352
+
353
+ </div>
354
+
355
+
356
+
357
+ <div id="foot">
358
+
359
+ <p><img src="../images/txt_copyright.png" width="136" height="15" alt="(C) H2O SPACE, Mynavi" /></p>
360
+
361
+ </div>
362
+
363
+
364
+
365
+ </div>
366
+
367
+ </body>
368
+
369
+ </html>
370
+
371
+
372
+
373
+ ```
374
+
375
+ ```php
376
+
377
+ //check_step5_1.php
378
+
379
+
380
+
381
+ <?php
382
+
383
+ session_start();
384
+
385
+ require('../dbconnect.php');
386
+
387
+
388
+
389
+ if (!isset($_SESSION['join'])) {
390
+
391
+ header('Location: index_step5_2.php');
392
+
393
+ exit();
394
+
395
+ }
396
+
397
+
398
+
399
+
204
400
 
205
401
  ?>
206
402
 
@@ -226,146 +422,76 @@
226
422
 
227
423
  <div id="wrap">
228
424
 
229
- <div id="head">
425
+ <div id="head">
230
-
426
+
231
- <h1>会員登録</h1>
427
+ <h1>会員登録</h1>
232
-
233
- </div>
234
-
235
-
236
-
237
- <div id="content">
238
-
239
-
240
-
241
- <p>次のフォームに必要事項をご記入ください。</p>
242
-
243
-
244
-
245
- <form action="" method="post" enctype="multipart/form-data">
246
-
247
- <dl>
248
-
249
- <dt>ニックネーム<span class="required">必須</span></dt>
250
-
251
- <dd>
252
-
253
- <input type="text" name="name" size="35" maxlength="255"
254
-
255
- value="<?php echo htmlspecialchars($input_name,
256
-
257
- ENT_QUOTES, 'UTF-8'); ?>" />
258
-
259
- <?php if ($input_name == 'blank'): ?>
260
-
261
- <p class="error">* ニックネームを入力してください</p>
262
-
263
- <?php endif; ?>
264
-
265
- </dd>
266
-
267
-
268
-
269
- <dt>メールアドレス<span class="required">必須</span></dt>
270
-
271
- <dd>
272
-
273
- <input type="text" name="email" size="35" maxlength="255"
274
-
275
- value="<?php echo htmlspecialchars($input_email,
276
-
277
- ENT_QUOTES, 'UTF-8'); ?>" />
278
-
279
- <?php if ($input_email == 'blank'): ?>
280
-
281
- <p class="error">* メールアドレスを入力してください</p>
282
-
283
- <?php endif; ?>
284
-
285
-
286
-
287
- <?php if ($input_email == 'duplicate'): ?>
288
-
289
- <p class="error">* 指定されたメールアドレスはすでに登録されています</p>
290
-
291
- <?php endif; ?>
292
-
293
- </dd>
294
-
295
-
296
-
297
- <dt>パスワード<span class="required">必須</span></dt>
298
-
299
- <dd>
300
-
301
- <input type="password" name="password" size="10" maxlength="20"
302
-
303
- value="<?php echo htmlspecialchars($input_password,
304
-
305
- ENT_QUOTES, 'UTF-8'); ?>" />
306
-
307
- <?php if ($input_password == 'blank'): ?>
308
-
309
- <p class="error">* パスワードを入力してください</p>
310
-
311
- <?php endif; ?>
312
-
313
-
314
-
315
- <?php if ($input_password == 'length'): ?>
316
-
317
- <p class="error">* パスワードは4文字以上で入力してください</p>
318
-
319
- <?php endif; ?>
320
-
321
- </dd>
322
-
323
-
324
-
325
- <dt>写真など</dt>
326
-
327
- <dd>
328
-
329
- <input type="file" name="image" size="35" value="test" />
330
-
331
-
332
-
333
- <?php if ($input_image == 'type'):?>
334
-
335
- <p class="error">* 写真などは「.gif」または「.jpg」の画像を指定してください</p>
336
-
337
- <?php endif; ?>
338
-
339
-
340
-
341
- <?php if (!empty($error)): ?>
342
-
343
- <p class="error">* 恐れ入りますが、画像を改めて指定してください</p>
344
-
345
- <?php endif; ?>
346
-
347
- </dd>
348
-
349
- </dl>
350
-
351
- <div><input type="submit" value="入力内容を確認する" /></div>
352
-
353
- </form>
354
-
355
- </div>
356
-
357
-
358
-
359
- <div id="foot">
360
-
361
- <p><img src="../images/txt_copyright.png" width="136" height="15" alt="(C) H2O SPACE, Mynavi" /></p>
362
-
363
- </div>
364
-
365
-
366
428
 
367
429
  </div>
368
430
 
431
+
432
+
433
+ <div id="content">
434
+
435
+ <p>記入した内容を確認して、「登録する」ボタンをクリックしてください</p>
436
+
437
+ <form action="" method="post">
438
+
439
+ <input type="hidden" name="action" value="submit" />
440
+
441
+ <dl>
442
+
443
+ <dt>ニックネーム</dt>
444
+
445
+ <dd>
446
+
447
+ <?php echo htmlspecialchars($_SESSION['join']['name'], ENT_QUOTES, 'UTF-8'); ?>
448
+
449
+ </dd>
450
+
451
+ <dt>メールアドレス</dt>
452
+
453
+ <dd>
454
+
455
+ <?php echo htmlspecialchars($_SESSION['join']['email'], ENT_QUOTES, 'UTF-8'); ?>
456
+
457
+ </dd>
458
+
459
+ <dt>パスワード</dt>
460
+
461
+ <dd>
462
+
463
+ 【表示されません】
464
+
465
+ </dd>
466
+
467
+ <dt>写真など</dt>
468
+
469
+ <dd>
470
+
471
+ <img src="../member_picture/<?php echo htmlspecialchars($_SESSION['join']['image'], ENT_QUOTES, 'UTF-8'); ?>" width="100" height="100" alt="" />
472
+
473
+ </dd>
474
+
475
+ </dl>
476
+
477
+ <div><a href="index.php?action=rewrite">&laquo;&nbsp;書き直す</a> | <input type="submit" value="登録する" /></div>
478
+
479
+ </form>
480
+
481
+ </div>
482
+
483
+
484
+
485
+ <div id="foot">
486
+
487
+ <p><img src="../images/txt_copyright.png" width="136" height="15" alt="(C) H2O Space. MYCOM" /></p>
488
+
489
+ </div>
490
+
491
+
492
+
493
+ </div>
494
+
369
495
  </body>
370
496
 
371
497
  </html>
@@ -373,131 +499,3 @@
373
499
 
374
500
 
375
501
  ```
376
-
377
- ```php
378
-
379
- //check_step5_1.php
380
-
381
-
382
-
383
- <?php
384
-
385
- session_start();
386
-
387
- require('../dbconnect.php');
388
-
389
-
390
-
391
- if (!isset($_SESSION['join'])) {
392
-
393
- header('Location: index_step5_2.php');
394
-
395
- exit();
396
-
397
- }
398
-
399
-
400
-
401
-
402
-
403
- ?>
404
-
405
-
406
-
407
- <!DOCTYPE>
408
-
409
- <html>
410
-
411
- <head>
412
-
413
- <meta charset="UTF-8" />
414
-
415
- <link rel="stylesheet" type="text/css" href="../style.css" />
416
-
417
- <title>会員登録</title>
418
-
419
- </head>
420
-
421
-
422
-
423
- <body>
424
-
425
- <div id="wrap">
426
-
427
- <div id="head">
428
-
429
- <h1>会員登録</h1>
430
-
431
- </div>
432
-
433
-
434
-
435
- <div id="content">
436
-
437
- <p>記入した内容を確認して、「登録する」ボタンをクリックしてください</p>
438
-
439
- <form action="" method="post">
440
-
441
- <input type="hidden" name="action" value="submit" />
442
-
443
- <dl>
444
-
445
- <dt>ニックネーム</dt>
446
-
447
- <dd>
448
-
449
- <?php echo htmlspecialchars($_SESSION['join']['name'], ENT_QUOTES, 'UTF-8'); ?>
450
-
451
- </dd>
452
-
453
- <dt>メールアドレス</dt>
454
-
455
- <dd>
456
-
457
- <?php echo htmlspecialchars($_SESSION['join']['email'], ENT_QUOTES, 'UTF-8'); ?>
458
-
459
- </dd>
460
-
461
- <dt>パスワード</dt>
462
-
463
- <dd>
464
-
465
- 【表示されません】
466
-
467
- </dd>
468
-
469
- <dt>写真など</dt>
470
-
471
- <dd>
472
-
473
- <img src="../member_picture/<?php echo htmlspecialchars($_SESSION['join']['image'], ENT_QUOTES, 'UTF-8'); ?>" width="100" height="100" alt="" />
474
-
475
- </dd>
476
-
477
- </dl>
478
-
479
- <div><a href="index.php?action=rewrite">&laquo;&nbsp;書き直す</a> | <input type="submit" value="登録する" /></div>
480
-
481
- </form>
482
-
483
- </div>
484
-
485
-
486
-
487
- <div id="foot">
488
-
489
- <p><img src="../images/txt_copyright.png" width="136" height="15" alt="(C) H2O Space. MYCOM" /></p>
490
-
491
- </div>
492
-
493
-
494
-
495
- </div>
496
-
497
- </body>
498
-
499
- </html>
500
-
501
-
502
-
503
- ```

2

修正

2019/12/31 09:33

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -32,9 +32,15 @@
32
32
 
33
33
 
34
34
 
35
+ 実行した後のURLは「php_sample/part5_2_sample/join/step5/index_step5_5.php?action=rewrite」です。
36
+
37
+ 実行後の画面です。
38
+
39
+
40
+
35
41
  ![イメージ説明](bb13523e200854d6aeff0546d9dd3a4b.jpeg)
36
42
 
37
-
43
+ 頂きましたネットは既に拝見済みですが、まだよく消化できていません。
38
44
 
39
45
 
40
46
 

1

追加

2019/12/31 09:06

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -32,7 +32,7 @@
32
32
 
33
33
 
34
34
 
35
-
35
+ ![イメージ説明](bb13523e200854d6aeff0546d9dd3a4b.jpeg)
36
36
 
37
37
 
38
38