關於課程
請輸入商品名稱:
<form action=”searchoutput.php” method=”post”>
<input type=”text” name=”keyword”>
<input type=”submit” value=”搜尋”>
</form>
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
<table>
<tr><th>商品編號</th><th>商品名稱</th><th>商品價格</th></tr>
<?php
$pdo=new PDO(‘mysql:host=localhost;dbname=shop;charset=utf8’,
‘root’, ‘12345678’);
$sql=$pdo->prepare(‘select * from product where name=?’);
$sql->execute([$_REQUEST[‘keyword’]]);
foreach ($sql->fetchAll() as $row) {
echo ‘<tr>’;
echo ‘<td>’, $row[‘id’], ‘</td>’;
echo ‘<td>’, $row[‘name’], ‘</td>’;
echo ‘<td>’, $row[‘price’], ‘</td>’;
echo ‘</tr>’;
}
?>
</table>