質問編集履歴
4
編集
test
CHANGED
File without changes
|
test
CHANGED
@@ -153,3 +153,137 @@
|
|
153
153
|
|
154
154
|
|
155
155
|
です
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
pdo_form.php
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
<?php
|
164
|
+
|
165
|
+
header("Content-type: text/html; charset=utf-8");
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
if(empty($_POST)) {
|
170
|
+
|
171
|
+
header("Location: pdo_form.html");
|
172
|
+
|
173
|
+
exit();
|
174
|
+
|
175
|
+
}else{
|
176
|
+
|
177
|
+
//名前入力判定
|
178
|
+
|
179
|
+
if (!isset($_POST['yourname']) || $_POST['yourname'] === "" ){
|
180
|
+
|
181
|
+
$errors['name'] = "名前が入力されていません。";
|
182
|
+
|
183
|
+
}
|
184
|
+
|
185
|
+
}
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
if(count($errors) === 0){
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
$dsn = 'mysql:host=localhost;dbname=test5;charset=utf8';
|
194
|
+
|
195
|
+
$user = 'root';
|
196
|
+
|
197
|
+
$password = '10veikA11#';
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
try{
|
202
|
+
|
203
|
+
$dbh = new PDO($dsn, $user, $password);
|
204
|
+
|
205
|
+
$statement = $dbh->prepare("INSERT INTO name (name) VALUES (:name)");
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
if($statement){
|
210
|
+
|
211
|
+
$yourname = $_POST['yourname'];
|
212
|
+
|
213
|
+
//プレースホルダへ実際の値を設定する
|
214
|
+
|
215
|
+
$statement->bindValue(':name', $yourname, PDO::PARAM_STR);
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
if(!$statement->execute()){
|
220
|
+
|
221
|
+
$errors['error'] = "登録失敗しました。";
|
222
|
+
|
223
|
+
}
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
//データベース接続切断
|
228
|
+
|
229
|
+
$dbh = null;
|
230
|
+
|
231
|
+
}
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
}catch (PDOException $e){
|
236
|
+
|
237
|
+
print('Error:'.$e->getMessage());
|
238
|
+
|
239
|
+
$errors['error'] = "データベース接続失敗しました。";
|
240
|
+
|
241
|
+
}
|
242
|
+
|
243
|
+
}
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
?>
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
<!DOCTYPE html>
|
252
|
+
|
253
|
+
<html>
|
254
|
+
|
255
|
+
<head>
|
256
|
+
|
257
|
+
<title>登録画面</title>
|
258
|
+
|
259
|
+
<meta charset="utf-8">
|
260
|
+
|
261
|
+
</head>
|
262
|
+
|
263
|
+
<body>
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
<?php if (count($errors) === 0): ?>
|
268
|
+
|
269
|
+
<p><?=htmlspecialchars($yourname, ENT_QUOTES, 'UTF-8')."さんで登録いたしました。"?></p>
|
270
|
+
|
271
|
+
<?php elseif(count($errors) > 0): ?>
|
272
|
+
|
273
|
+
<?php
|
274
|
+
|
275
|
+
foreach($errors as $value){
|
276
|
+
|
277
|
+
echo "<p>".$value."</p>";
|
278
|
+
|
279
|
+
}
|
280
|
+
|
281
|
+
?>
|
282
|
+
|
283
|
+
<?php endif; ?>
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
</body>
|
288
|
+
|
289
|
+
</html>
|
3
編集
test
CHANGED
File without changes
|
test
CHANGED
@@ -56,7 +56,7 @@
|
|
56
56
|
|
57
57
|
$user = 'root';
|
58
58
|
|
59
|
-
$password = '
|
59
|
+
$password = 'root';
|
60
60
|
|
61
61
|
|
62
62
|
|
2
編集
test
CHANGED
File without changes
|
test
CHANGED
@@ -15,3 +15,141 @@
|
|
15
15
|
|
16
16
|
|
17
17
|
![イメージ説明](4bc4766683bc4b0c35e2f58ac47a41fe.jpeg)
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
pdo_form.html
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
<?php
|
26
|
+
|
27
|
+
header("Content-type: text/html; charset=utf-8");
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
if(empty($_POST)) {
|
32
|
+
|
33
|
+
header("Location: pdo_form.html");
|
34
|
+
|
35
|
+
exit();
|
36
|
+
|
37
|
+
}else{
|
38
|
+
|
39
|
+
//名前入力判定
|
40
|
+
|
41
|
+
if (!isset($_POST['yourname']) || $_POST['yourname'] === "" ){
|
42
|
+
|
43
|
+
$errors['name'] = "名前が入力されていません。";
|
44
|
+
|
45
|
+
}
|
46
|
+
|
47
|
+
}
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
if(count($errors) === 0){
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
$dsn = 'mysql:host=localhost;dbname=test5;charset=utf8';
|
56
|
+
|
57
|
+
$user = 'root';
|
58
|
+
|
59
|
+
$password = '10veikA11#';
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
try{
|
64
|
+
|
65
|
+
$dbh = new PDO($dsn, $user, $password);
|
66
|
+
|
67
|
+
$statement = $dbh->prepare("INSERT INTO name (name) VALUES (:name)");
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
if($statement){
|
72
|
+
|
73
|
+
$yourname = $_POST['yourname'];
|
74
|
+
|
75
|
+
//プレースホルダへ実際の値を設定する
|
76
|
+
|
77
|
+
$statement->bindValue(':name', $yourname, PDO::PARAM_STR);
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
if(!$statement->execute()){
|
82
|
+
|
83
|
+
$errors['error'] = "登録失敗しました。";
|
84
|
+
|
85
|
+
}
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
//データベース接続切断
|
90
|
+
|
91
|
+
$dbh = null;
|
92
|
+
|
93
|
+
}
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
}catch (PDOException $e){
|
98
|
+
|
99
|
+
print('Error:'.$e->getMessage());
|
100
|
+
|
101
|
+
$errors['error'] = "データベース接続失敗しました。";
|
102
|
+
|
103
|
+
}
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
?>
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
<!DOCTYPE html>
|
114
|
+
|
115
|
+
<html>
|
116
|
+
|
117
|
+
<head>
|
118
|
+
|
119
|
+
<title>登録画面</title>
|
120
|
+
|
121
|
+
<meta charset="utf-8">
|
122
|
+
|
123
|
+
</head>
|
124
|
+
|
125
|
+
<body>
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
<?php if (count($errors) === 0): ?>
|
130
|
+
|
131
|
+
<p><?=htmlspecialchars($yourname, ENT_QUOTES, 'UTF-8')."さんで登録いたしました。"?></p>
|
132
|
+
|
133
|
+
<?php elseif(count($errors) > 0): ?>
|
134
|
+
|
135
|
+
<?php
|
136
|
+
|
137
|
+
foreach($errors as $value){
|
138
|
+
|
139
|
+
echo "<p>".$value."</p>";
|
140
|
+
|
141
|
+
}
|
142
|
+
|
143
|
+
?>
|
144
|
+
|
145
|
+
<?php endif; ?>
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
</body>
|
150
|
+
|
151
|
+
</html>
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
です
|
1
画像追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -7,3 +7,11 @@
|
|
7
7
|
|
8
8
|
|
9
9
|
それとも どこでもいいのでしょうか?
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
下のようにコードがそのまま表示されます
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
![イメージ説明](4bc4766683bc4b0c35e2f58ac47a41fe.jpeg)
|