PHP的資料庫增刪改查原始碼(2)

來源:互聯網
上載者:User

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>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.