質問編集履歴

3

文章追加

2017/08/20 04:32

投稿

dog57
dog57

スコア131

test CHANGED
File without changes
test CHANGED
@@ -16,500 +16,494 @@
16
16
 
17
17
  ###発生している問題・エラーメッセージ
18
18
 
19
+ (上記画像参照願います。)
20
+
21
+
22
+
23
+ ###該当のソースコード
24
+
25
+ トップ画像(上記画像)index.html
26
+
27
+ ```html
28
+
29
+ <!DOCTYPE html>
30
+
31
+ <html lang="ja">
32
+
33
+ <head>
34
+
35
+
36
+
37
+ <meta charset="UTF-8">
38
+
39
+ <title>My Web Site</title>
40
+
41
+ <link rel="stylesheet" href="style.css">
42
+
43
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js">
44
+
45
+
46
+
47
+ </script>
48
+
49
+
50
+
51
+ </head>
52
+
53
+ <body>
54
+
55
+
56
+
57
+
58
+
59
+ <header>
60
+
61
+
62
+
63
+ <div class="header-left">
64
+
65
+ <img class="logo" src="https://www.fastpic.jp/images.php?file=3519571152.jpg" alt="ロゴ画像">
66
+
67
+ </div>
68
+
69
+
70
+
71
+ <div class="header-right">
72
+
73
+ <a href="http://onepiece-naruto.com/blog-category-12.html" class="login" target="_blank"><p class="login1">ログイン</p></a>
74
+
75
+ </div>
76
+
77
+
78
+
79
+
80
+
81
+ </header>
82
+
83
+
84
+
85
+
86
+
87
+ <div class="main">
88
+
89
+
90
+
91
+ <h1>行ってみたい<span>国</span>一覧</h1>
92
+
93
+ <form class="research" action="search.php" method="post">
94
+
95
+ <input class="research" size="40" type="text" name="検索" value="入力してください">
96
+
97
+ <input class="research" type="submit" name="nation" value="検索"><br>
98
+
99
+ <a href="index2.html"><input class="research" type="button" name="btn" value="新規登録"></a>
100
+
101
+ </form>
102
+
103
+
104
+
105
+
106
+
107
+ </div>
108
+
109
+
110
+
111
+
112
+
113
+ <div class="wrapper">
114
+
115
+
116
+
117
+
118
+
119
+
120
+
121
+ <table border="1">
122
+
123
+
124
+
125
+ <tr>
126
+
127
+ <th class="head">順位</th>
128
+
129
+ <th class="head">国名</th>
130
+
131
+ <th class="head">食べたい食べ物</th>
132
+
133
+ <th class="head">理由</th>
134
+
135
+ <th class="head"></th>
136
+
137
+ </tr>
138
+
139
+
140
+
141
+
142
+
143
+ <tr>
144
+
145
+ <td>1位</td>
146
+
147
+ <td>スペイン</td>
148
+
149
+ <td>パエリア</td>
150
+
151
+ <td>サッカーを見たいから</td>
152
+
153
+ <td><a href="#">編集</a> <a href="#">削除</a></td>
154
+
155
+ </tr>
156
+
157
+
158
+
159
+ <tr>
160
+
161
+ <td>2位</td>
162
+
163
+ <td>アメリカ</td>
164
+
165
+ <td>グリルロブスター</td>
166
+
167
+ <td>ダンスの文化を知りたいから</td>
168
+
169
+ <td><a href="#">編集</a> <a href="#">削除</a></td>
170
+
171
+ </tr>
172
+
173
+
174
+
175
+ <tr>
176
+
177
+ <td>3位</td>
178
+
179
+ <td>インド</td>
180
+
181
+ <td>カレーライス</td>
182
+
183
+ <td>発展途上の国を間近で見てみたいから</td>
184
+
185
+ <td><a href="#">編集</a> <a href="#">削除</a></td>
186
+
187
+ </tr>
188
+
189
+
190
+
191
+ <tr>
192
+
193
+ <td>4位</td>
194
+
195
+ <td>タイ</td>
196
+
197
+ <td>ガパオ</td>
198
+
199
+ <td>バンコクの発展具合を見てみたいから</td>
200
+
201
+ <td><a href="#">編集</a> <a href="#">削除</a></td>
202
+
203
+ </tr>
204
+
205
+
206
+
207
+ <tr>
208
+
209
+ <td>5位</td>
210
+
211
+ <td>フィリピン</td>
212
+
213
+ <td>アドボ </td>
214
+
215
+ <td>友達が楽しそうに働いているから</td>
216
+
217
+ <td><a href="#">編集</a> <a href="#">削除</a></td>
218
+
219
+ </tr>
220
+
221
+
222
+
223
+
224
+
225
+
226
+
227
+ </table>
228
+
229
+
230
+
231
+ </div>
232
+
233
+
234
+
235
+
236
+
237
+
238
+
239
+
240
+
241
+
242
+
243
+
244
+
245
+ <footer>
246
+
247
+
248
+
249
+
250
+
251
+ <div class="footer-left">
252
+
253
+ <img src="https://www.fastpic.jp/images.php?file=3519571152.jpg" alt="ロゴ画像">
254
+
255
+ <p>&copy travel enjoy.</p>
256
+
257
+ </div>
258
+
259
+
260
+
261
+ <div class="footer-list">
262
+
263
+ <ul>
264
+
265
+ <li><a href="https://www.airbnb.jp/">利用規約</a></li>
266
+
267
+ <li><a href="https://www.uber.com/ja-JP/">プライバシー</a></li>
268
+
269
+ <li><a href="https://tabelog.com/tokyo/A1307/A130701/13191934/">アクセシビリティ</a></li>
270
+
271
+ </ul>
272
+
273
+ </div>
274
+
275
+
276
+
277
+
278
+
279
+
280
+
281
+ </footer>
282
+
283
+
284
+
285
+ <script src="script.js">
286
+
287
+
288
+
289
+ </script>
290
+
291
+
292
+
293
+
294
+
295
+ </body>
296
+
297
+ </html>
298
+
299
+
300
+
19
301
  ```
20
302
 
303
+
304
+
305
+ 検索結果画面(search.php)
306
+
307
+ ```php
308
+
309
+ <?php
310
+
311
+
312
+
313
+ $nation = $_POST["nation"];
314
+
315
+
316
+
317
+ header("Content-type: text/html; charset=utf-8");
318
+
319
+
320
+
321
+ if(empty($_POST)) {
322
+
323
+ header("Location: search.php");
324
+
325
+ exit();
326
+
327
+ }else{
328
+
329
+ //国名入力判定
330
+
331
+ if (!isset($_POST['nation']) || $_POST['nation'] === "" ){
332
+
333
+ $errors['country'] = "国名が入力されていません。";
334
+
335
+ }
336
+
337
+ }
338
+
339
+
340
+
341
+ if(count($errors) === 0){
342
+
343
+
344
+
345
+ $dsn = 'mysql:host=localhost;dbname=uriage;charset=utf8';
346
+
347
+ $user = 'andrew';
348
+
349
+ $password = 'andrew135';
350
+
351
+
352
+
353
+ try{
354
+
355
+
356
+
357
+ $dbh = new PDO($dsn, $user, $password);
358
+
359
+ $statement = $dbh->prepare("SELECT * FROM nation WHERE country");
360
+
361
+
362
+
363
+ if($statement){
364
+
365
+ $nation = $_POST['nation'];
366
+
367
+ $like_nation = "%".$nation."%";
368
+
369
+ //プレースホルダへ実際の値を設定する
370
+
371
+ $statement->bindValue(':nation', $like_nation, PDO::PARAM_STR);
372
+
373
+
374
+
375
+ if($statement->execute()){
376
+
377
+ //レコード件数取得
378
+
379
+ $row_count = $statement->rowCount();
380
+
381
+
382
+
383
+ while($row = $statement->fetch()){
384
+
385
+ $rows[] = $row;
386
+
387
+ }
388
+
389
+
390
+
391
+ }else{
392
+
393
+ $errors['error'] = "検索失敗しました。";
394
+
395
+ }
396
+
397
+
398
+
399
+ //データベース接続切断
400
+
401
+ $pdo = null;
402
+
403
+ }
404
+
405
+
406
+
407
+ }catch (PDOException $e){
408
+
409
+ print('Error:'.$e->getMessage());
410
+
411
+ $errors['error'] = "データベース接続失敗しました。";
412
+
413
+ }
414
+
415
+ }
416
+
417
+
418
+
419
+ ?>
420
+
421
+
422
+
423
+ <!DOCTYPE html>
424
+
425
+ <html>
426
+
427
+ <head>
428
+
429
+ <title>検索結果</title>
430
+
431
+ <meta charset="utf-8">
432
+
433
+ </head>
434
+
435
+ <body>
436
+
437
+
438
+
439
+ <?php if (count($errors) === 0): ?>
440
+
441
+
442
+
443
+ <p><?=htmlspecialchars($yourname, ENT_QUOTES, 'UTF-8')."さんで検索しました。"?></p>
444
+
445
+ <p><?=$row_count?>件です。</p>
446
+
447
+
448
+
449
+ <table border='1'>
450
+
451
+ <tr><td>id</td><td>nation</td></tr>
452
+
453
+
454
+
455
+ <?php
456
+
457
+ foreach($rows as $row){
458
+
459
+ ?>
460
+
21
- 検索失敗しました。
461
+ <tr>
462
+
22
-
463
+ <td><?=$row['id']?></td>
464
+
23
- PHP Notice: Undefined variable: errors in /home/vagrant/public_php/search.php on line 17
465
+ <td><?=htmlspecialchars($row['nation'],ENT_QUOTES,'UTF-8')?></td>
466
+
467
+ </tr>
468
+
469
+ <?php
470
+
471
+ }
472
+
473
+ ?>
474
+
475
+
476
+
477
+ <?php elseif(count($errors) > 0): ?>
478
+
479
+ <?php
480
+
481
+ foreach($errors as $value){
482
+
483
+ echo "<p>".$value."</p>";
484
+
485
+ }
486
+
487
+ ?>
488
+
489
+ <?php endif; ?>
490
+
491
+
492
+
493
+
494
+
495
+
496
+
497
+ </body>
498
+
499
+ </html>
500
+
501
+
24
502
 
25
503
  ```
26
504
 
27
505
 
28
506
 
29
- ###該当のソースコード
30
-
31
- トップ画像(上記画像)index.html
32
-
33
- ```html
34
-
35
- <!DOCTYPE html>
36
-
37
- <html lang="ja">
38
-
39
- <head>
40
-
41
-
42
-
43
- <meta charset="UTF-8">
44
-
45
- <title>My Web Site</title>
46
-
47
- <link rel="stylesheet" href="style.css">
48
-
49
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js">
50
-
51
-
52
-
53
- </script>
54
-
55
-
56
-
57
- </head>
58
-
59
- <body>
60
-
61
-
62
-
63
-
64
-
65
- <header>
66
-
67
-
68
-
69
- <div class="header-left">
70
-
71
- <img class="logo" src="https://www.fastpic.jp/images.php?file=3519571152.jpg" alt="ロゴ画像">
72
-
73
- </div>
74
-
75
-
76
-
77
- <div class="header-right">
78
-
79
- <a href="http://onepiece-naruto.com/blog-category-12.html" class="login" target="_blank"><p class="login1">ログイン</p></a>
80
-
81
- </div>
82
-
83
-
84
-
85
-
86
-
87
- </header>
88
-
89
-
90
-
91
-
92
-
93
- <div class="main">
94
-
95
-
96
-
97
- <h1>行ってみたい<span>国</span>一覧</h1>
98
-
99
- <form class="research" action="search.php" method="post">
100
-
101
- <input class="research" size="40" type="text" name="検索" value="入力してください">
102
-
103
- <input class="research" type="submit" name="nation" value="検索"><br>
104
-
105
- <a href="index2.html"><input class="research" type="button" name="btn" value="新規登録"></a>
106
-
107
- </form>
108
-
109
-
110
-
111
-
112
-
113
- </div>
114
-
115
-
116
-
117
-
118
-
119
- <div class="wrapper">
120
-
121
-
122
-
123
-
124
-
125
-
126
-
127
- <table border="1">
128
-
129
-
130
-
131
- <tr>
132
-
133
- <th class="head">順位</th>
134
-
135
- <th class="head">国名</th>
136
-
137
- <th class="head">食べたい食べ物</th>
138
-
139
- <th class="head">理由</th>
140
-
141
- <th class="head"></th>
142
-
143
- </tr>
144
-
145
-
146
-
147
-
148
-
149
- <tr>
150
-
151
- <td>1位</td>
152
-
153
- <td>スペイン</td>
154
-
155
- <td>パエリア</td>
156
-
157
- <td>サッカーを見たいから</td>
158
-
159
- <td><a href="#">編集</a> <a href="#">削除</a></td>
160
-
161
- </tr>
162
-
163
-
164
-
165
- <tr>
166
-
167
- <td>2位</td>
168
-
169
- <td>アメリカ</td>
170
-
171
- <td>グリルロブスター</td>
172
-
173
- <td>ダンスの文化を知りたいから</td>
174
-
175
- <td><a href="#">編集</a> <a href="#">削除</a></td>
176
-
177
- </tr>
178
-
179
-
180
-
181
- <tr>
182
-
183
- <td>3位</td>
184
-
185
- <td>インド</td>
186
-
187
- <td>カレーライス</td>
188
-
189
- <td>発展途上の国を間近で見てみたいから</td>
190
-
191
- <td><a href="#">編集</a> <a href="#">削除</a></td>
192
-
193
- </tr>
194
-
195
-
196
-
197
- <tr>
198
-
199
- <td>4位</td>
200
-
201
- <td>タイ</td>
202
-
203
- <td>ガパオ</td>
204
-
205
- <td>バンコクの発展具合を見てみたいから</td>
206
-
207
- <td><a href="#">編集</a> <a href="#">削除</a></td>
208
-
209
- </tr>
210
-
211
-
212
-
213
- <tr>
214
-
215
- <td>5位</td>
216
-
217
- <td>フィリピン</td>
218
-
219
- <td>アドボ </td>
220
-
221
- <td>友達が楽しそうに働いているから</td>
222
-
223
- <td><a href="#">編集</a> <a href="#">削除</a></td>
224
-
225
- </tr>
226
-
227
-
228
-
229
-
230
-
231
-
232
-
233
- </table>
234
-
235
-
236
-
237
- </div>
238
-
239
-
240
-
241
-
242
-
243
-
244
-
245
-
246
-
247
-
248
-
249
-
250
-
251
- <footer>
252
-
253
-
254
-
255
-
256
-
257
- <div class="footer-left">
258
-
259
- <img src="https://www.fastpic.jp/images.php?file=3519571152.jpg" alt="ロゴ画像">
260
-
261
- <p>&copy travel enjoy.</p>
262
-
263
- </div>
264
-
265
-
266
-
267
- <div class="footer-list">
268
-
269
- <ul>
270
-
271
- <li><a href="https://www.airbnb.jp/">利用規約</a></li>
272
-
273
- <li><a href="https://www.uber.com/ja-JP/">プライバシー</a></li>
274
-
275
- <li><a href="https://tabelog.com/tokyo/A1307/A130701/13191934/">アクセシビリティ</a></li>
276
-
277
- </ul>
278
-
279
- </div>
280
-
281
-
282
-
283
-
284
-
285
-
286
-
287
- </footer>
288
-
289
-
290
-
291
- <script src="script.js">
292
-
293
-
294
-
295
- </script>
296
-
297
-
298
-
299
-
300
-
301
- </body>
302
-
303
- </html>
304
-
305
-
306
-
307
- ```
308
-
309
-
310
-
311
- 検索結果画面(search.php)
312
-
313
- ```php
314
-
315
- <?php
316
-
317
-
318
-
319
- $nation = $_POST["nation"];
320
-
321
-
322
-
323
- header("Content-type: text/html; charset=utf-8");
324
-
325
-
326
-
327
- if(empty($_POST)) {
328
-
329
- header("Location: search.php");
330
-
331
- exit();
332
-
333
- }else{
334
-
335
- //国名入力判定
336
-
337
- if (!isset($_POST['nation']) || $_POST['nation'] === "" ){
338
-
339
- $errors['country'] = "国名が入力されていません。";
340
-
341
- }
342
-
343
- }
344
-
345
-
346
-
347
- if(count($errors) === 0){
348
-
349
-
350
-
351
- $dsn = 'mysql:host=localhost;dbname=uriage;charset=utf8';
352
-
353
- $user = 'andrew';
354
-
355
- $password = 'andrew135';
356
-
357
-
358
-
359
- try{
360
-
361
-
362
-
363
- $dbh = new PDO($dsn, $user, $password);
364
-
365
- $statement = $dbh->prepare("SELECT * FROM nation WHERE country");
366
-
367
-
368
-
369
- if($statement){
370
-
371
- $nation = $_POST['nation'];
372
-
373
- $like_nation = "%".$nation."%";
374
-
375
- //プレースホルダへ実際の値を設定する
376
-
377
- $statement->bindValue(':nation', $like_nation, PDO::PARAM_STR);
378
-
379
-
380
-
381
- if($statement->execute()){
382
-
383
- //レコード件数取得
384
-
385
- $row_count = $statement->rowCount();
386
-
387
-
388
-
389
- while($row = $statement->fetch()){
390
-
391
- $rows[] = $row;
392
-
393
- }
394
-
395
-
396
-
397
- }else{
398
-
399
- $errors['error'] = "検索失敗しました。";
400
-
401
- }
402
-
403
-
404
-
405
- //データベース接続切断
406
-
407
- $pdo = null;
408
-
409
- }
410
-
411
-
412
-
413
- }catch (PDOException $e){
414
-
415
- print('Error:'.$e->getMessage());
416
-
417
- $errors['error'] = "データベース接続失敗しました。";
418
-
419
- }
420
-
421
- }
422
-
423
-
424
-
425
- ?>
426
-
427
-
428
-
429
- <!DOCTYPE html>
430
-
431
- <html>
432
-
433
- <head>
434
-
435
- <title>検索結果</title>
436
-
437
- <meta charset="utf-8">
438
-
439
- </head>
440
-
441
- <body>
442
-
443
-
444
-
445
- <?php if (count($errors) === 0): ?>
446
-
447
-
448
-
449
- <p><?=htmlspecialchars($yourname, ENT_QUOTES, 'UTF-8')."さんで検索しました。"?></p>
450
-
451
- <p><?=$row_count?>件です。</p>
452
-
453
-
454
-
455
- <table border='1'>
456
-
457
- <tr><td>id</td><td>nation</td></tr>
458
-
459
-
460
-
461
- <?php
462
-
463
- foreach($rows as $row){
464
-
465
- ?>
466
-
467
- <tr>
468
-
469
- <td><?=$row['id']?></td>
470
-
471
- <td><?=htmlspecialchars($row['nation'],ENT_QUOTES,'UTF-8')?></td>
472
-
473
- </tr>
474
-
475
- <?php
476
-
477
- }
478
-
479
- ?>
480
-
481
-
482
-
483
- <?php elseif(count($errors) > 0): ?>
484
-
485
- <?php
486
-
487
- foreach($errors as $value){
488
-
489
- echo "<p>".$value."</p>";
490
-
491
- }
492
-
493
- ?>
494
-
495
- <?php endif; ?>
496
-
497
-
498
-
499
-
500
-
501
-
502
-
503
- </body>
504
-
505
- </html>
506
-
507
-
508
-
509
- ```
510
-
511
-
512
-
513
507
  ###試したこと
514
508
 
515
509
  プリペアステートメントの中身が違うかと思い、コーディングを見直したが違った。

2

画像の変更

2017/08/20 04:32

投稿

dog57
dog57

スコア131

test CHANGED
File without changes
test CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  ![イメージ説明](bc7cf1b133f53a3fa6ee3f1f3b757e33.png)
12
12
 
13
- ![イメージ説明](b9e32e5470f212cfb960b061eb5aaddc.png)
13
+ ![イメージ説明](809ed1154ac64ce695d7e16aa7e1dd2d.png)
14
14
 
15
15
 
16
16
 

1

画像の追加

2017/08/20 04:31

投稿

dog57
dog57

スコア131

test CHANGED
File without changes
test CHANGED
@@ -10,6 +10,8 @@
10
10
 
11
11
  ![イメージ説明](bc7cf1b133f53a3fa6ee3f1f3b757e33.png)
12
12
 
13
+ ![イメージ説明](b9e32e5470f212cfb960b061eb5aaddc.png)
14
+
13
15
 
14
16
 
15
17
  ###発生している問題・エラーメッセージ