index.php修改部分程式

<form id="form1" name="form1">
<table border="1">
<tr>
<td>id</td>
<td>name</td>
<td>tel</td>
<td>address</td>
<td>修改</td>
<td>刪除</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_result['id']; ?></td>
<td><?php echo $row_result['name']; ?></td>
<td><?php echo $row_result['tel']; ?></td>
<td><?php echo $row_result['address']; ?></td>
<td>修改</td>
<td><a href="del.php?id=<? echo $row_result[id]; ?>">刪除</a></td>
</tr>
<?php } while ($row_result = mysql_fetch_assoc($result));?>
<tr>

</table>
</form>

 

del.php

<?php
$hostname_restaurant = "localhost";//
$database_restaurant = "restaurant";//
$username_restaurant = "kai";//
$password_restaurant = "admin";//
$link = mysql_pconnect($hostname_restaurant, $username_restaurant, $password_restaurant) or trigger_error(mysql_error(),E_USER_ERROR);
//使用 mysql_pconnect()而不使用mysql_connect( ) 可以省下每次重新開啟資料庫連接的時間

mysql_query("set names utf8");//將資料庫設定為utf8編碼,防止中文亂碼


$sql ="DELETE FROM taipei_eat WHERE id=".$_GET[id];

$result = mysql_query($sql, $link) or die(mysql_error()); //執行sql語法

mysql_close($link); //關閉資料庫連結

header( "location:index.php"); //回index.php

?>

 

參考資料:http://muta1021.wordpress.com/category/php/

相关文章