質問編集履歴
1
コード追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,61 +14,383 @@
|
|
14
14
|
|
15
15
|
```
|
16
16
|
|
17
|
-
|
17
|
+
<?php
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
require_once(__DIR__.'/config.php');
|
22
|
+
|
23
|
+
require_once(__DIR__ . '/Regist1.php');
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
try{
|
28
|
+
|
29
|
+
$customer = new \MyApp\Customer();
|
30
|
+
|
31
|
+
}catch(Exception $e){
|
32
|
+
|
33
|
+
$e->getMessage();
|
34
|
+
|
35
|
+
exit;
|
36
|
+
|
37
|
+
}
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
if($_SERVER['REQUEST_METHOD']=="POST"){
|
42
|
+
|
43
|
+
$mail = $_POST['mail'];
|
44
|
+
|
45
|
+
$sql = "select count(mail) from customer where mail = '$mail";
|
46
|
+
|
47
|
+
$stmt = $customer->getDB()->prepare($sql);
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
if(empty($_POST['mail'])){
|
52
|
+
|
53
|
+
$mail_err = "メールアドレスが未入力";
|
54
|
+
|
55
|
+
}else if(empty($_POST['pass'])){
|
56
|
+
|
57
|
+
$pass_err = "パスワードが未入力";
|
58
|
+
|
59
|
+
}else if($STMT >0){
|
60
|
+
|
61
|
+
$mail_err = $mail."は重複してます";
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
}else{
|
66
|
+
|
67
|
+
$pass = $_POST['pass'];
|
68
|
+
|
69
|
+
$sex = $_POST['sex'];
|
70
|
+
|
71
|
+
$year = $_POST['year'];
|
72
|
+
|
73
|
+
$month = $_POST['month'];
|
74
|
+
|
75
|
+
$day = $_POST['day'];
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
$customer->post();
|
80
|
+
|
81
|
+
}
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
}
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
?>
|
92
|
+
|
93
|
+
<!DOCTYPE html>
|
94
|
+
|
95
|
+
<html lang="ja">
|
96
|
+
|
97
|
+
<head>
|
98
|
+
|
99
|
+
<meta charset="utf-8">
|
100
|
+
|
101
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
102
|
+
|
103
|
+
<title>Port forio</title>
|
104
|
+
|
105
|
+
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
|
106
|
+
|
107
|
+
<link rel="stylesheet" href="css/style.css">
|
108
|
+
|
109
|
+
<link rel="stylesheet" href="css/regist.css">
|
110
|
+
|
111
|
+
</head>
|
112
|
+
|
113
|
+
<body>
|
114
|
+
|
115
|
+
<header>
|
116
|
+
|
117
|
+
<div class="header container">
|
118
|
+
|
119
|
+
<nav class="navbar navbar-expand-sm navbar-light">
|
120
|
+
|
121
|
+
<a href="/" class="navbar-brand">TOP</a>
|
122
|
+
|
123
|
+
<button class="navbar-toggler" data-toggle="collapse" data-target="#menu">
|
124
|
+
|
125
|
+
<span class="navbar-toggler-icon"></span>
|
126
|
+
|
127
|
+
</button>
|
128
|
+
|
129
|
+
<div id="menu" class="collapse navbar-collapse">
|
130
|
+
|
131
|
+
<ul class="navbar-nav">
|
132
|
+
|
133
|
+
<li class="nav-item"><a href="/regist.php" class="nav-link">新規登録</a></li>
|
134
|
+
|
135
|
+
<li class="nav-item"><a href="#" class="nav-link">ログイン</a></li>
|
136
|
+
|
137
|
+
<li class="nav-item"><a href="/profile.php" class="nav-link">プロフィール</a></li>
|
138
|
+
|
139
|
+
<li class="nav-item"><a href="/check.php" class="nav-link">診断</a></li>
|
140
|
+
|
141
|
+
<li class="nav-item"><a href="/task.php" class="nav-link">管理</a></li>
|
142
|
+
|
143
|
+
</ul>
|
144
|
+
|
145
|
+
</nav>
|
146
|
+
|
147
|
+
</div>
|
148
|
+
|
149
|
+
<form action="" class="form-inline m-4 search">
|
150
|
+
|
151
|
+
<input type="search" class="form-control mr-2" placeholder="検索">
|
152
|
+
|
153
|
+
<button class="btn btn-primary">検索</button>
|
154
|
+
|
155
|
+
</div>
|
156
|
+
|
157
|
+
</form>
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
</header>
|
162
|
+
|
163
|
+
<main>
|
164
|
+
|
165
|
+
<h1>新規登録</h1>
|
166
|
+
|
167
|
+
<form action="/customers.php" method="post">
|
168
|
+
|
169
|
+
<div>
|
170
|
+
|
171
|
+
<?php if(isset($mail_err)):?>
|
172
|
+
|
173
|
+
<?= $mail_err;?>
|
174
|
+
|
175
|
+
<?php elseif(isset($pass_err)):?>
|
176
|
+
|
177
|
+
<?= $pass_err;?>
|
178
|
+
|
179
|
+
<?php else:?>
|
180
|
+
|
181
|
+
<table>
|
182
|
+
|
183
|
+
<tr>
|
184
|
+
|
185
|
+
<td>1)メールアドレス</td>
|
186
|
+
|
187
|
+
<td name="mail"><?= $mail;?></td>
|
188
|
+
|
189
|
+
</tr>
|
190
|
+
|
191
|
+
<tr>
|
192
|
+
|
193
|
+
<td>2)パスワード</td>
|
194
|
+
|
195
|
+
<td name="pass"><?= $pass;?></td>
|
196
|
+
|
197
|
+
</tr>
|
198
|
+
|
199
|
+
<tr>
|
200
|
+
|
201
|
+
<td>3)性別</td>
|
202
|
+
|
203
|
+
<td name="sex"><?= $sex;?></td>
|
204
|
+
|
205
|
+
</tr>
|
206
|
+
|
207
|
+
<tr>
|
208
|
+
|
209
|
+
<td>4)生年月日</td>
|
210
|
+
|
211
|
+
<td name="birthday"><?= $birthday;?></td>
|
212
|
+
|
213
|
+
</tr>
|
214
|
+
|
215
|
+
</tbody>
|
216
|
+
|
217
|
+
</table>
|
218
|
+
|
219
|
+
<?php endif;?>
|
220
|
+
|
221
|
+
</div>
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
</from>
|
226
|
+
|
227
|
+
<button><a href="/regist.php">戻る</a></button>
|
228
|
+
|
229
|
+
</main>
|
230
|
+
|
231
|
+
<footer>
|
232
|
+
|
233
|
+
<a href="/form.php" id="form">問い合わせ</a>
|
234
|
+
|
235
|
+
</footer>
|
236
|
+
|
237
|
+
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
|
238
|
+
|
239
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
|
240
|
+
|
241
|
+
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
|
242
|
+
|
243
|
+
<script src = " https://code.jquery.com/jquery-3.0.0.js " ></script>
|
244
|
+
|
245
|
+
<script src = " https://code.jquery.com/jquery-migrate-3.1.0.js " ></script>
|
246
|
+
|
247
|
+
<script src="js/task.js"></script>
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
</body>
|
252
|
+
|
253
|
+
</html>
|
18
254
|
|
19
255
|
```
|
20
256
|
|
257
|
+
```
|
258
|
+
|
259
|
+
<?php
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
namespace MyApp;
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
class Customer{
|
268
|
+
|
269
|
+
private $_db;
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
public function __construct(){
|
274
|
+
|
275
|
+
$this->_connectDB();
|
276
|
+
|
277
|
+
}
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
public function post(){
|
282
|
+
|
283
|
+
try{
|
284
|
+
|
285
|
+
$this->_save();
|
286
|
+
|
287
|
+
header('Location: http://'.$_SERVER['HTTP_HOST'].'/customers.php');
|
288
|
+
|
289
|
+
}catch(\Exception $e){
|
290
|
+
|
291
|
+
$_SESSION['err'] = $e->getMessage();
|
292
|
+
|
293
|
+
header('Location: http://' . $_SERVER['HTTP_HOST'].'/regist.php');
|
294
|
+
|
295
|
+
}
|
296
|
+
|
297
|
+
exit;
|
298
|
+
|
299
|
+
}
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
public function getError(){
|
304
|
+
|
305
|
+
$err = null;
|
306
|
+
|
307
|
+
if(isset($_SESSION['err'])){
|
308
|
+
|
309
|
+
$err = $_SESSION['err'];
|
310
|
+
|
311
|
+
unset($_SESSION['err']);
|
312
|
+
|
313
|
+
}
|
314
|
+
|
315
|
+
return $err;
|
316
|
+
|
317
|
+
}
|
318
|
+
|
319
|
+
|
320
|
+
|
321
|
+
private function _save(){
|
322
|
+
|
323
|
+
$sql = "insert into customer (mail,Password,sex,Birthday) values (:mail,:Password,:sex,:Birthday)";
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
$Birthday = $_POST['year']."/".$_POST['month']."/".$_POST['day'];
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
$stmt = $this->_db->prepare($sql);
|
332
|
+
|
333
|
+
$stmt->bindValue(':mail',$_POST['mail'],\PDO::PARAM_STR);
|
334
|
+
|
335
|
+
$stmt->bindValue(':Password',$_POST['pass'],\PDO::PARAM_STR);
|
336
|
+
|
337
|
+
$stmt->bindValue(':sex',$_POST['sex'],\PDO::PARAM_INT);
|
338
|
+
|
339
|
+
$stmt->bindValue(':Birthday',$Birthday,\PDO::PARAM_STR);
|
340
|
+
|
341
|
+
|
342
|
+
|
343
|
+
try{
|
344
|
+
|
345
|
+
$stmt->execute();
|
346
|
+
|
347
|
+
}catch(\PDOException $e){
|
348
|
+
|
349
|
+
throw new \Exception('No insert!');
|
350
|
+
|
351
|
+
}
|
352
|
+
|
353
|
+
}
|
354
|
+
|
355
|
+
|
356
|
+
|
357
|
+
public function getDB(){
|
358
|
+
|
359
|
+
return $this->_db;
|
360
|
+
|
361
|
+
}
|
362
|
+
|
363
|
+
private function _connectDB(){
|
364
|
+
|
365
|
+
try{
|
366
|
+
|
367
|
+
$this->_db = new \PDO(DSN,DB_USERNAME,DB_PASSWORD);
|
368
|
+
|
369
|
+
$this->_db->setAttribute(\PDO::ATTR_ERRMODE,\PDO::ERRMODE_EXCEPTION);
|
370
|
+
|
371
|
+
}catch(\PDOException $e){
|
372
|
+
|
373
|
+
throw new \Exception('Failed to connect DB');
|
374
|
+
|
375
|
+
}
|
376
|
+
|
377
|
+
}
|
378
|
+
|
379
|
+
}
|
380
|
+
|
381
|
+
|
382
|
+
|
383
|
+
|
384
|
+
|
385
|
+
```
|
386
|
+
|
21
387
|
|
22
388
|
|
23
389
|
### 該当のソースコード
|
24
390
|
|
25
391
|
|
26
392
|
|
27
|
-
|
393
|
+
|
28
|
-
|
29
|
-
if($_SERVER['REQUEST_METHOD']=="POST"){
|
30
|
-
|
31
|
-
$mail = $_POST['mail'];
|
32
|
-
|
33
|
-
$sql = "select count(mail) from customer where mail = '$mail";
|
34
|
-
|
35
|
-
$stmt = $customer->getDB()->prepare($sql);
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
if(empty($_POST['mail'])){
|
40
|
-
|
41
|
-
$mail_err = "メールアドレスが未入力";
|
42
|
-
|
43
|
-
}else if(empty($_POST['pass'])){
|
44
|
-
|
45
|
-
$pass_err = "パスワードが未入力";
|
46
|
-
|
47
|
-
}else if($stmt > 0 ){
|
48
|
-
|
49
|
-
$mail_err = $mail."は重複してます";
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
}else{
|
54
|
-
|
55
|
-
$pass = $_POST['pass'];
|
56
|
-
|
57
|
-
$sex = $_POST['sex'];
|
58
|
-
|
59
|
-
$year = $_POST['year'];
|
60
|
-
|
61
|
-
$month = $_POST['month'];
|
62
|
-
|
63
|
-
$day = $_POST['day'];
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
$customer->post();
|
68
|
-
|
69
|
-
}
|
70
|
-
|
71
|
-
```
|
72
394
|
|
73
395
|
|
74
396
|
|