質問編集履歴
4
修正前と修正後のコードを書きました
test
CHANGED
File without changes
|
test
CHANGED
@@ -20,7 +20,7 @@
|
|
20
20
|
|
21
21
|
###該当のソースコード
|
22
22
|
|
23
|
-
|
23
|
+
```
|
24
24
|
|
25
25
|
<!-- input.php -->
|
26
26
|
|
@@ -110,117 +110,223 @@
|
|
110
110
|
|
111
111
|
|
112
112
|
|
113
|
-
|
113
|
+
```
|
114
|
+
|
115
|
+
修正前
|
116
|
+
|
117
|
+
```
|
118
|
+
|
119
|
+
<!-- input_do.php -->
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
<?php
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
try{
|
128
|
+
|
129
|
+
$pdo = new PDO('mysql:host=localhost;dbname=mydb;charset=utf8','root','suzusaga');
|
130
|
+
|
131
|
+
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
132
|
+
|
133
|
+
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
$stmt = $pdo->prepare('INSERT INTO my_items (maker_id, item_name, price, keyword) VALUES (:maker_id, :item_name, :price, :keyword)');
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
$maker_id = htmlspecialchars($_POST["$d%"]);
|
142
|
+
|
143
|
+
$item_name = htmlspecialchars($_POST["%s%"]);
|
144
|
+
|
145
|
+
$price = htmlspecialchars($_POST["%d%"]);
|
146
|
+
|
147
|
+
$keyword = htmlspecialchars($_POST["%s"]);
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
$stmt->bindValue('maker_id', $maker_id);
|
152
|
+
|
153
|
+
$stmt->bindParam('item_name', $item_name);
|
154
|
+
|
155
|
+
$stmt->bindValue('price', $price);
|
156
|
+
|
157
|
+
$stmt->bindParam('keyword', $keyword);
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
$stmt->execute();
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
}
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
catch(PDOException $Exception) {
|
170
|
+
|
171
|
+
die('接続エラー:'.$Exception->getMessage());
|
172
|
+
|
173
|
+
}
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
?>
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
<!DOCTYPE html>
|
182
|
+
|
183
|
+
<html>
|
184
|
+
|
185
|
+
<head>
|
186
|
+
|
187
|
+
<meta charset="utf-8">
|
188
|
+
|
189
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
190
|
+
|
191
|
+
<title></title>
|
192
|
+
|
193
|
+
<link rel="stylesheet" href="">
|
194
|
+
|
195
|
+
</head>
|
196
|
+
|
197
|
+
<body>
|
198
|
+
|
199
|
+
<p>登録完了しました。</p>
|
200
|
+
|
201
|
+
<p><a href="input.php">TOPに戻る</a></p>
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
</body>
|
206
|
+
|
207
|
+
</html>
|
208
|
+
|
209
|
+
```
|
210
|
+
|
211
|
+
修正後
|
212
|
+
|
213
|
+
```ここに言語を入力
|
214
|
+
|
215
|
+
<!-- input_do.php -->
|
216
|
+
|
217
|
+
<?php
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
try{
|
222
|
+
|
223
|
+
$pdo = new PDO('mysql:host=localhost;dbname=mydb;charset=utf8','root','suzusaga');
|
224
|
+
|
225
|
+
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
226
|
+
|
227
|
+
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
|
228
|
+
|
229
|
+
$sql = "SELECT * FROM my_items ORDER BY id DESC";
|
230
|
+
|
231
|
+
$stmt = $pdo->query($sql);
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
print "接続に成功しました"."<br>";
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
$stmt = $pdo->prepare('INSERT INTO my_items (maker_id, item_name, price, keyword) VALUES (:maker_id, :item_name, :price, :keyword)');
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
$maker_id = htmlspecialchars($_POST["maker_id"]);
|
244
|
+
|
245
|
+
$item_name = htmlspecialchars($_POST["item_name"]);
|
246
|
+
|
247
|
+
$price = htmlspecialchars($_POST["price"]);
|
248
|
+
|
249
|
+
$keyword = htmlspecialchars($_POST["keyword"]);
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
$stmt->bindValue(':maker_id', $maker_id);
|
254
|
+
|
255
|
+
$stmt->bindValue(':item_name', $item_name);
|
256
|
+
|
257
|
+
$stmt->bindValue(':price', $price);
|
258
|
+
|
259
|
+
$stmt->bindValue(':keyword', $keyword);
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
$stmt->execute();
|
264
|
+
|
265
|
+
var_dump($maker_id);
|
266
|
+
|
267
|
+
var_dump($item_name);
|
268
|
+
|
269
|
+
var_dump($price);
|
270
|
+
|
271
|
+
var_dump($keyword);
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
}
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
catch(PDOException $Exception) {
|
280
|
+
|
281
|
+
die('接続エラー:'.$Exception->getMessage());
|
282
|
+
|
283
|
+
}
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
?>
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
<!DOCTYPE html>
|
292
|
+
|
293
|
+
<html>
|
294
|
+
|
295
|
+
<head>
|
296
|
+
|
297
|
+
<meta charset="utf-8">
|
298
|
+
|
299
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
300
|
+
|
301
|
+
<title></title>
|
302
|
+
|
303
|
+
<link rel="stylesheet" href="">
|
304
|
+
|
305
|
+
</head>
|
306
|
+
|
307
|
+
<body>
|
308
|
+
|
309
|
+
<p>登録完了しました。</p>
|
310
|
+
|
311
|
+
<p><a href="input.php">TOPに戻る</a></p>
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
</body>
|
316
|
+
|
317
|
+
</html>
|
318
|
+
|
319
|
+
```
|
320
|
+
|
321
|
+
|
114
322
|
|
115
323
|
|
116
324
|
|
117
|
-
|
325
|
+
|
118
|
-
|
119
|
-
|
326
|
+
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
327
|
+
|
124
|
-
|
125
|
-
|
328
|
+
|
126
|
-
|
127
|
-
|
329
|
+
|
128
|
-
|
129
|
-
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
|
130
|
-
|
131
|
-
$sql = "SELECT * FROM my_items ORDER BY id DESC";
|
132
|
-
|
133
|
-
$stmt = $pdo->query($sql);
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
print "接続に成功しました"."<br>";
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
$stmt = $pdo->prepare('INSERT INTO my_items (maker_id, item_name, price, keyword) VALUES (:maker_id, :item_name, :price, :keyword)');
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
$maker_id = htmlspecialchars($_POST["maker_id"]);
|
146
|
-
|
147
|
-
$item_name = htmlspecialchars($_POST["item_name"]);
|
148
|
-
|
149
|
-
$price = htmlspecialchars($_POST["price"]);
|
150
|
-
|
151
|
-
$keyword = htmlspecialchars($_POST["keyword"]);
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
$stmt->bindValue(':maker_id', $maker_id);
|
156
|
-
|
157
|
-
$stmt->bindValue(':item_name', $item_name);
|
158
|
-
|
159
|
-
$stmt->bindValue(':price', $price);
|
160
|
-
|
161
|
-
$stmt->bindValue(':keyword', $keyword);
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
$stmt->execute();
|
166
|
-
|
167
|
-
var_dump($maker_id);
|
168
|
-
|
169
|
-
var_dump($item_name);
|
170
|
-
|
171
|
-
var_dump($price);
|
172
|
-
|
173
|
-
var_dump($keyword);
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
}
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
catch(PDOException $Exception) {
|
182
|
-
|
183
|
-
die('接続エラー:'.$Exception->getMessage());
|
184
|
-
|
185
|
-
}
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
?>
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
<!DOCTYPE html>
|
194
|
-
|
195
|
-
<html>
|
196
|
-
|
197
|
-
<head>
|
198
|
-
|
199
|
-
<meta charset="utf-8">
|
200
|
-
|
201
|
-
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
202
|
-
|
203
|
-
<title></title>
|
204
|
-
|
205
|
-
<link rel="stylesheet" href="">
|
206
|
-
|
207
|
-
</head>
|
208
|
-
|
209
|
-
<body>
|
210
|
-
|
211
|
-
<p>登録完了しました。</p>
|
212
|
-
|
213
|
-
<p><a href="input.php">TOPに戻る</a></p>
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
</body>
|
218
|
-
|
219
|
-
</html>
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
```
|
224
330
|
|
225
331
|
|
226
332
|
|
3
文法の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -154,11 +154,11 @@
|
|
154
154
|
|
155
155
|
$stmt->bindValue(':maker_id', $maker_id);
|
156
156
|
|
157
|
-
$stmt->bind
|
157
|
+
$stmt->bindValue(':item_name', $item_name);
|
158
158
|
|
159
159
|
$stmt->bindValue(':price', $price);
|
160
160
|
|
161
|
-
$stmt->bind
|
161
|
+
$stmt->bindValue(':keyword', $keyword);
|
162
162
|
|
163
163
|
|
164
164
|
|
2
文法の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -128,6 +128,12 @@
|
|
128
128
|
|
129
129
|
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
|
130
130
|
|
131
|
+
$sql = "SELECT * FROM my_items ORDER BY id DESC";
|
132
|
+
|
133
|
+
$stmt = $pdo->query($sql);
|
134
|
+
|
135
|
+
|
136
|
+
|
131
137
|
print "接続に成功しました"."<br>";
|
132
138
|
|
133
139
|
|
@@ -136,28 +142,36 @@
|
|
136
142
|
|
137
143
|
|
138
144
|
|
139
|
-
$maker_id = htmlspecialchars($_POST["
|
145
|
+
$maker_id = htmlspecialchars($_POST["maker_id"]);
|
140
|
-
|
146
|
+
|
141
|
-
$item_name = htmlspecialchars($_POST["
|
147
|
+
$item_name = htmlspecialchars($_POST["item_name"]);
|
142
|
-
|
148
|
+
|
143
|
-
$price = htmlspecialchars($_POST["
|
149
|
+
$price = htmlspecialchars($_POST["price"]);
|
144
|
-
|
150
|
+
|
145
|
-
$keyword = htmlspecialchars($_POST["
|
151
|
+
$keyword = htmlspecialchars($_POST["keyword"]);
|
146
|
-
|
147
|
-
|
148
|
-
|
152
|
+
|
153
|
+
|
154
|
+
|
149
|
-
$stmt->bindValue('maker_id', $maker_id);
|
155
|
+
$stmt->bindValue(':maker_id', $maker_id);
|
150
|
-
|
156
|
+
|
151
|
-
$stmt->bindParam('item_name', $item_name);
|
157
|
+
$stmt->bindParam(':item_name', $item_name);
|
152
|
-
|
158
|
+
|
153
|
-
$stmt->bindValue('price', $price);
|
159
|
+
$stmt->bindValue(':price', $price);
|
154
|
-
|
160
|
+
|
155
|
-
$stmt->bindParam('keyword', $keyword);
|
161
|
+
$stmt->bindParam(':keyword', $keyword);
|
156
162
|
|
157
163
|
|
158
164
|
|
159
165
|
$stmt->execute();
|
160
166
|
|
167
|
+
var_dump($maker_id);
|
168
|
+
|
169
|
+
var_dump($item_name);
|
170
|
+
|
171
|
+
var_dump($price);
|
172
|
+
|
173
|
+
var_dump($keyword);
|
174
|
+
|
161
175
|
|
162
176
|
|
163
177
|
}
|
1
文法の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -20,6 +20,8 @@
|
|
20
20
|
|
21
21
|
###該当のソースコード
|
22
22
|
|
23
|
+
```
|
24
|
+
|
23
25
|
<!-- input.php -->
|
24
26
|
|
25
27
|
<!DOCTYPE html>
|
@@ -108,6 +110,10 @@
|
|
108
110
|
|
109
111
|
|
110
112
|
|
113
|
+
```
|
114
|
+
|
115
|
+
|
116
|
+
|
111
117
|
<!-- input_do.php -->
|
112
118
|
|
113
119
|
<?php
|
@@ -122,6 +128,8 @@
|
|
122
128
|
|
123
129
|
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
|
124
130
|
|
131
|
+
print "接続に成功しました"."<br>";
|
132
|
+
|
125
133
|
|
126
134
|
|
127
135
|
$stmt = $pdo->prepare('INSERT INTO my_items (maker_id, item_name, price, keyword) VALUES (:maker_id, :item_name, :price, :keyword)');
|
@@ -198,7 +206,7 @@
|
|
198
206
|
|
199
207
|
|
200
208
|
|
201
|
-
|
209
|
+
```
|
202
210
|
|
203
211
|
|
204
212
|
|