PHP與mysql的問題
如圖
想要在這個mysql_result.php網頁中加入刪除使用者帳號密碼的功能,將他改變如下圖,讓他能夠點擊[刪除]
這個超連結,就能刪除掉那一行的值
請問各位要怎麼做呢??
以下是mysql_result.php的源碼
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>顯示所有記錄</title>
</head>
<body>
<h1 align="CENTER">帳號密碼顯示表</h1>
<?php
require_once("mysql.php");
$link = create_connection();
$sql = "SELECT no AS '編號',username AS '帳號',password AS '密碼' FROM root";
$result = execute_sql("os", $sql, $link);
echo "<table border='1' align='center'><tr align='center'>";
for ($i = 0; $i < mysql_num_fields($result); $i++)
echo "<td>" . mysql_fetch_field($result, $i)->name. "</td>";
echo "</tr>";
for ($j = 0; $j < mysql_num_rows($result); $j++)
{
echo "<tr>";
for ($k = 0; $k < mysql_num_fields($result); $k++)
echo "<td>" . mysql_result($result, $j, $k) . "</td>";
echo "</tr>";
}
echo "</table>" ;
mysql_free_result($result);
mysql_close($link);
?>
</body>
</html>
<?php
function create_connection()
{
$link = mysql_connect("localhost","root","")
or die("無法連接" . mysql_error());
mysql_query("SET NAMES utf8");
return $link;
}
function execute_sql($database,$sql,$link)
{
$db_selected = mysql_select_db($database,$link)
or die("無法開啟" . mysql_error($link));
$result = mysql_query($sql,$link);
return $result;
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>顯示所有記錄</title>
</head>
<body>
<h1 align="CENTER">帳號密碼顯示表</h1>
<?php
require_once("mysql.php");
$link = create_connection();
if(isset($_GET['del'])) {
$sql = "delete from root ehere no=$_GET[del]";
$result = execute_sql("os", $sql, $link);
}
$sql = "SELECT no AS '編號',username AS '帳號',password AS '密碼' FROM root";
$result = execute_sql("os", $sql, $link);
echo "<table border='1' align='center'><tr align='center'>";
for ($i = 0; $i < mysql_num_fields($result); $i++)
echo "<td>" . mysql_fetch_field($result, $i)->name. "</td>";
echo "<td>操作</td>";
echo "</tr>";
for ($j = 0; $j < mysql_num_rows($result); $j++)
{
echo "<tr>";
for ($k = 0; $k < mysql_num_fields($result); $k++)
echo "<td>" . mysql_result($result, $j, $k) . "</td>";
echo "<td><a = href=?del=" . mysql_result($result, $j, 0) . "</td>";
echo "</tr>";
}
echo "</table>" ;
mysql_free_result($result);
mysql_close($link);
?>
</body>
</html>