1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

昨日頂いた指摘をもとに修正しました

Last updated at Posted at 2018-03-30

昨日頂いた指摘の修正

index.php
foreach ($db->query($sql) as $row) {
   array_push($stmt,$row);
 }

の部分はfetchAllで処理する形にしました。
sqlはプレスホルダで処理をするという記事をたくさん見たので、下記のような形に変えました。
エスケープは実行部分で使用するという記事を見たので変更。

index.php
<?php
require_once('db_info.php');
 $statement = $db->prepare("SELECT * FROM 画像 WHERE nam LIKE (:nam) ");
 if($statement){
	 //プレースホルダへ実際の値を設定する
	 $statement->bindValue(':nam', "%".htmlspecialchars($_GET['search'],ENT_QUOTES,'UTF-8')."%", PDO::PARAM_STR);
 }
 $statement->execute();
 $result = $statement->fetchAll();
 ?>
 <!DOCTYPE html>
 <html>
   <head>
     <meta charset="utf-8">
     <title>記事の検索</title>
   </head>
   <body>
     <form action="" method="get">
       <p>記事の検索</p>
       <input type="text" name="search" placeholder="<?=htmlspecialchars($_GET['search'],ENT_QUOTES,'UTF-8') ?>"><br>
       <input type="submit" name="" value="検索">
     </form>
		 <?php foreach ($result as  $value): ?>
			 <p><?php echo $value['nam'] ?><br>
			 <?php echo $value['dat']; ?></p>
		 <?php endforeach; ?>
   </body>
 </html>

こちらのサイトを参考に訂正して見ましたー。
様々なご指摘ありがとうございます!
https://www.websec-room.com/2013/12/17/1339

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?