1<?php2ini_set('display_errors',1);3error_reporting(E_ALL);45if($_SERVER['REQUEST_METHOD']==='POST'){6if(!empty(filter_input(INPUT_POST,'name'))){7$name=filter_input(INPUT_POST,'name');8try{9$pdo=newPDO('mysql:host=localhost;dbname=test;charset=utf8','root','password');10$stmt=$pdo->prepare('SELECT * FROM `name` WHERE `name` = :name');11$stmt->bindParam(':name',$name);12$stmt->execute();13$result=$stmt->fetchAll(PDO::FETCH_ASSOC);14}catch(PDOException$exception){15echo$exception->getMessage();16exit();17}18}19}20?>21<!DOCTYPEhtml>22<html>23<head>24<metacharset='utf-8'>25<title>タイトル</title>26</head>27<body>28<formaction=''method='post'>29<label>30<inputtype='text'name='name'>31</label>32<inputtype='submit'>33</form>34<divid="result">35<?phpif($_SERVER['REQUEST_METHOD']==='POST'){?>36<?phpif(empty($result)){?>37<strong>該当する結果はなし。</strong>38<?php}else{?>39<ol>40<?phpforeach($resultas&$value){?>41<li><?phpechohtmlspecialchars($value['id'],ENT_QUOTES,'UTF-8')." : ".htmlspecialchars($value['name'],ENT_QUOTES,'UTF-8')?></li>42<?php}?>43</ol>44<?php}?>45<?php}?>46</div>47</body>48</html>