質問編集履歴
1
コード追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -6,12 +6,18 @@
|
|
6
6
|
### 発生している問題・エラーメッセージ
|
7
7
|
$stmt > 0の条件の処理がうまくいかない
|
8
8
|
```
|
9
|
+
<?php
|
9
10
|
|
10
|
-
|
11
|
+
require_once(__DIR__.'/config.php');
|
12
|
+
require_once(__DIR__ . '/Regist1.php');
|
11
13
|
|
14
|
+
try{
|
15
|
+
$customer = new \MyApp\Customer();
|
16
|
+
}catch(Exception $e){
|
12
|
-
|
17
|
+
$e->getMessage();
|
18
|
+
exit;
|
19
|
+
}
|
13
20
|
|
14
|
-
```php
|
15
21
|
if($_SERVER['REQUEST_METHOD']=="POST"){
|
16
22
|
$mail = $_POST['mail'];
|
17
23
|
$sql = "select count(mail) from customer where mail = '$mail";
|
@@ -21,7 +27,7 @@
|
|
21
27
|
$mail_err = "メールアドレスが未入力";
|
22
28
|
}else if(empty($_POST['pass'])){
|
23
29
|
$pass_err = "パスワードが未入力";
|
24
|
-
}else if($
|
30
|
+
}else if($STMT >0){
|
25
31
|
$mail_err = $mail."は重複してます";
|
26
32
|
|
27
33
|
}else{
|
@@ -33,8 +39,163 @@
|
|
33
39
|
|
34
40
|
$customer->post();
|
35
41
|
}
|
42
|
+
|
43
|
+
|
44
|
+
}
|
45
|
+
|
46
|
+
?>
|
47
|
+
<!DOCTYPE html>
|
48
|
+
<html lang="ja">
|
49
|
+
<head>
|
50
|
+
<meta charset="utf-8">
|
51
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
52
|
+
<title>Port forio</title>
|
53
|
+
<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">
|
54
|
+
<link rel="stylesheet" href="css/style.css">
|
55
|
+
<link rel="stylesheet" href="css/regist.css">
|
56
|
+
</head>
|
57
|
+
<body>
|
58
|
+
<header>
|
59
|
+
<div class="header container">
|
60
|
+
<nav class="navbar navbar-expand-sm navbar-light">
|
61
|
+
<a href="/" class="navbar-brand">TOP</a>
|
62
|
+
<button class="navbar-toggler" data-toggle="collapse" data-target="#menu">
|
63
|
+
<span class="navbar-toggler-icon"></span>
|
64
|
+
</button>
|
65
|
+
<div id="menu" class="collapse navbar-collapse">
|
66
|
+
<ul class="navbar-nav">
|
67
|
+
<li class="nav-item"><a href="/regist.php" class="nav-link">新規登録</a></li>
|
68
|
+
<li class="nav-item"><a href="#" class="nav-link">ログイン</a></li>
|
69
|
+
<li class="nav-item"><a href="/profile.php" class="nav-link">プロフィール</a></li>
|
70
|
+
<li class="nav-item"><a href="/check.php" class="nav-link">診断</a></li>
|
71
|
+
<li class="nav-item"><a href="/task.php" class="nav-link">管理</a></li>
|
72
|
+
</ul>
|
73
|
+
</nav>
|
74
|
+
</div>
|
75
|
+
<form action="" class="form-inline m-4 search">
|
76
|
+
<input type="search" class="form-control mr-2" placeholder="検索">
|
77
|
+
<button class="btn btn-primary">検索</button>
|
78
|
+
</div>
|
79
|
+
</form>
|
80
|
+
|
81
|
+
</header>
|
82
|
+
<main>
|
83
|
+
<h1>新規登録</h1>
|
84
|
+
<form action="/customers.php" method="post">
|
85
|
+
<div>
|
86
|
+
<?php if(isset($mail_err)):?>
|
87
|
+
<?= $mail_err;?>
|
88
|
+
<?php elseif(isset($pass_err)):?>
|
89
|
+
<?= $pass_err;?>
|
90
|
+
<?php else:?>
|
91
|
+
<table>
|
92
|
+
<tr>
|
93
|
+
<td>1)メールアドレス</td>
|
94
|
+
<td name="mail"><?= $mail;?></td>
|
95
|
+
</tr>
|
96
|
+
<tr>
|
97
|
+
<td>2)パスワード</td>
|
98
|
+
<td name="pass"><?= $pass;?></td>
|
99
|
+
</tr>
|
100
|
+
<tr>
|
101
|
+
<td>3)性別</td>
|
102
|
+
<td name="sex"><?= $sex;?></td>
|
103
|
+
</tr>
|
104
|
+
<tr>
|
105
|
+
<td>4)生年月日</td>
|
106
|
+
<td name="birthday"><?= $birthday;?></td>
|
107
|
+
</tr>
|
108
|
+
</tbody>
|
109
|
+
</table>
|
110
|
+
<?php endif;?>
|
111
|
+
</div>
|
112
|
+
|
113
|
+
</from>
|
114
|
+
<button><a href="/regist.php">戻る</a></button>
|
115
|
+
</main>
|
116
|
+
<footer>
|
117
|
+
<a href="/form.php" id="form">問い合わせ</a>
|
118
|
+
</footer>
|
119
|
+
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
|
120
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
|
121
|
+
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
|
122
|
+
<script src = " https://code.jquery.com/jquery-3.0.0.js " ></script>
|
123
|
+
<script src = " https://code.jquery.com/jquery-migrate-3.1.0.js " ></script>
|
124
|
+
<script src="js/task.js"></script>
|
125
|
+
|
126
|
+
</body>
|
127
|
+
</html>
|
36
128
|
```
|
129
|
+
```
|
130
|
+
<?php
|
37
131
|
|
132
|
+
namespace MyApp;
|
133
|
+
|
134
|
+
class Customer{
|
135
|
+
private $_db;
|
136
|
+
|
137
|
+
public function __construct(){
|
138
|
+
$this->_connectDB();
|
139
|
+
}
|
140
|
+
|
141
|
+
public function post(){
|
142
|
+
try{
|
143
|
+
$this->_save();
|
144
|
+
header('Location: http://'.$_SERVER['HTTP_HOST'].'/customers.php');
|
145
|
+
}catch(\Exception $e){
|
146
|
+
$_SESSION['err'] = $e->getMessage();
|
147
|
+
header('Location: http://' . $_SERVER['HTTP_HOST'].'/regist.php');
|
148
|
+
}
|
149
|
+
exit;
|
150
|
+
}
|
151
|
+
|
152
|
+
public function getError(){
|
153
|
+
$err = null;
|
154
|
+
if(isset($_SESSION['err'])){
|
155
|
+
$err = $_SESSION['err'];
|
156
|
+
unset($_SESSION['err']);
|
157
|
+
}
|
158
|
+
return $err;
|
159
|
+
}
|
160
|
+
|
161
|
+
private function _save(){
|
162
|
+
$sql = "insert into customer (mail,Password,sex,Birthday) values (:mail,:Password,:sex,:Birthday)";
|
163
|
+
|
164
|
+
$Birthday = $_POST['year']."/".$_POST['month']."/".$_POST['day'];
|
165
|
+
|
166
|
+
$stmt = $this->_db->prepare($sql);
|
167
|
+
$stmt->bindValue(':mail',$_POST['mail'],\PDO::PARAM_STR);
|
168
|
+
$stmt->bindValue(':Password',$_POST['pass'],\PDO::PARAM_STR);
|
169
|
+
$stmt->bindValue(':sex',$_POST['sex'],\PDO::PARAM_INT);
|
170
|
+
$stmt->bindValue(':Birthday',$Birthday,\PDO::PARAM_STR);
|
171
|
+
|
172
|
+
try{
|
173
|
+
$stmt->execute();
|
174
|
+
}catch(\PDOException $e){
|
175
|
+
throw new \Exception('No insert!');
|
176
|
+
}
|
177
|
+
}
|
178
|
+
|
179
|
+
public function getDB(){
|
180
|
+
return $this->_db;
|
181
|
+
}
|
182
|
+
private function _connectDB(){
|
183
|
+
try{
|
184
|
+
$this->_db = new \PDO(DSN,DB_USERNAME,DB_PASSWORD);
|
185
|
+
$this->_db->setAttribute(\PDO::ATTR_ERRMODE,\PDO::ERRMODE_EXCEPTION);
|
186
|
+
}catch(\PDOException $e){
|
187
|
+
throw new \Exception('Failed to connect DB');
|
188
|
+
}
|
189
|
+
}
|
190
|
+
}
|
191
|
+
|
192
|
+
|
193
|
+
```
|
194
|
+
|
195
|
+
### 該当のソースコード
|
196
|
+
|
197
|
+
|
198
|
+
|
38
199
|
### 試したこと
|
39
200
|
var_dump($stmt)で中身を確認した。
|
40
201
|
ここに問題に対して試したことを記載してください。
|