關於課程
<table>
<tr><th>商品編號</th><th>商品名稱</th><th>商品價格</th></tr>
<?php
$pdo=new PDO(‘mysql:host=localhost;dbname=shop;charset=utf8’,
‘root’, ‘12345678’);
foreach ($pdo->query(‘select * from product’) as $row) {
echo ‘<tr>’;
echo ‘<td>’, $row[‘id’], ‘</td>’;
echo ‘<td>’, $row[‘name’], ‘</td>’;
echo ‘<td>’, $row[‘price’], ‘</td>’;
echo ‘<td>’;
echo ‘<a href=”deleteoutput.php?id=’, $row[‘id’], ‘”>確定刪除</a>’;
echo ‘</td>’;
echo ‘</tr>’;
}
?>
</table>
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
<?php
$pdo=new PDO(‘mysql:host=localhost;dbname=shop;charset=utf8’,
‘root’, ‘12345678’);
$sql=$pdo->prepare(‘delete from product where id=?’);
if ($sql->execute([$_REQUEST[‘id’]])) {
echo ‘刪除成功。’;
} else {
echo ‘刪除失敗。’;
}
?>