3.更新
<html>
<body>
<title>
更新
</title>
<?
//PHP程序的開始
$db = MySQL_connect("localhost", "root");
MySQL_select_db("mysite",$db);
if (!$id)
{
$result = MySQL_query("SELECT * FROM user",$db);
if ($myrow = MySQL_fetch_array($result))
{
printf("<h2 align=left>請選擇要修改的用戶名字:</h2>");
do {
printf("%s<a href="%s?id=%s">%s </a><br>\n",
$myrow["id"],$PATH_INFO,$myrow["id"], $myrow["name"]);
}
while ($myrow = MySQL_fetch_array($result));
}
else
{
echo "對不起!數據庫中沒有記錄";
}
}
else
{
if ($submit)
{
$sql = "UPDATE user SET name='$name',city='$city',
address='$address',email='$email' WHERE id=$id";
$result = MySQL_query($sql);
echo "謝謝!數據更改完成\n";
}
else
{
$sql = "SELECT * FROM user WHERE id=$id";
$result = MySQL_query($sql);
$myrow = MySQL_fetch_array($result);
//以下不是PHP的部分
?>
<h2 align=left>請對用戶的信息進行修改:</h2>
<form method="post" action="<? echo $PATH_INFO ?>">
<input type=hidden name="id"
value="<?php echo $myrow["id"] ?>">
姓名:<input type="Text" name="first" value="<?php
echo $myrow["name"] ?>"><br>
城市:<input type="Text" name="city" value="<?php echo
$myrow["city"] ?>"><br>
住址:<input type="Text" name="address" value="<?php echo
$myrow["address"] ?>"><br>
電子郵件:<input type="Text" name="email" value="<?php echo
$myrow["email"] ?>"><br>
<input type="Submit" name="submit" value="修改完畢">
</form>
<?
//PHP 的結束
65:}
}
?>
</body>
</html>