質問編集履歴

1

コピーミスで抜けていた「$id = htmlspecialchars($_POST["id"]);」を直しました

2018/08/23 09:19

投稿

Mcworter
Mcworter

スコア13

test CHANGED
File without changes
test CHANGED
@@ -149,3 +149,115 @@
149
149
  PHP Version 7.2.7
150
150
 
151
151
  10.1.34-MariaDB
152
+
153
+
154
+
155
+ ###追記!!!!
156
+
157
+
158
+
159
+ コピーする際に
160
+
161
+ 「$id = htmlspecialchars($_POST["id"]);」
162
+
163
+ が抜けてしまいました;;
164
+
165
+
166
+
167
+ 大変申し訳ないです。
168
+
169
+
170
+
171
+ ### 本来のソースコード
172
+
173
+
174
+
175
+ ```PHP
176
+
177
+ <?php
178
+
179
+
180
+
181
+ // Your code here!
182
+
183
+ try{
184
+
185
+
186
+
187
+ $pdo = new PDO(
188
+
189
+ 'mysql:host=127.0.0.1;dbname=test;charset=utf8',
190
+
191
+ "root",
192
+
193
+ "",
194
+
195
+ [
196
+
197
+ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
198
+
199
+ PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
200
+
201
+ ]
202
+
203
+ );
204
+
205
+
206
+
207
+ } catch (PDOException $e){
208
+
209
+ header('Content-Type: text/plain; charset=utf8', true, 500);
210
+
211
+ exit($e->getMessage());
212
+
213
+ }
214
+
215
+
216
+
217
+ $id = htmlspecialchars($_POST["id"]);
218
+
219
+
220
+
221
+ $username_sql = 'SELECT user_name FROM users WHERE id = ?';
222
+
223
+ $stmt = $pdo -> prepare($username_sql);
224
+
225
+ $stmt -> bindvalue(1,$id,PDO::PARAM_STR);
226
+
227
+ $username = $stmt -> execute();
228
+
229
+
230
+
231
+ echo "あなたの名前は".$username."です。"
232
+
233
+
234
+
235
+ ?>
236
+
237
+
238
+
239
+ <!DOCTYPE html>
240
+
241
+ <html>
242
+
243
+ <head>
244
+
245
+ <title>Page Title</title>
246
+
247
+ <body>
248
+
249
+ <form class="" action="sousin.php" method="post">
250
+
251
+ <label for="id">ユーザーID:</label>
252
+
253
+ <input type="text" name="id" id="id">
254
+
255
+ <input type="submit" value="ログイン">
256
+
257
+ </form>
258
+
259
+ </body>
260
+
261
+ </html>
262
+
263
+ ```