php修改更新資料庫使用者記錄的函數

來源:互聯網
上載者:User

$link_id = mysql_connect("localhist","root","qwaszx") or die("串連失敗!");
if($link_id)
{
 mysql_select_db("my_test");
 if(!$_GET[id])
 {
  $result = mysql_query("select * from userinfo");
  echo "<TABLE border = 1>
   <TR>
   <TD>編號</TD>
   <TD>使用者名稱稱</TD>
   <TD>性別</TD>
   <TD>年齡</TD>
   <TD>註冊時間</TD>
   <TD>操作</TD>
   </TR>";
  while($row = mysql_fetch_array($result))
  {
   echo "<TR>
    <TD>".$row[id]."</TD>
    <TD>".$row[uername]."</TD>
    <TD>".$row[gender]."</TD>
    <TD>".$row[age]."</TD>
    <TD>".$row[regdate]."</TD>
    <TD><a href = modify.php?id = ".$row[id].">編輯</a></TD>
    </TR>";
  }
  echo "</TABLE>";
 }else
 {
  if(!$_POST[ok])
  {
   $sql = "select * frim userinfo where id = ".$_GET[id];
   $result = mysql_query($sql);
   $row = mysql_fetch_array($result);
   ?>
            <form method = post action = 'modify.php?id = <? echo $_GET[id];?>'>
            <?
   echo $row[id]."<br>";
   ?>
            <INPUT TYPE = "hidden" name = "id" value = <? echo $row[id];?>>
            姓名 <input type = text name = "uername" value = <? echo $row[uername];?>><br>
            性別 <input type = text name = "gender" value = <? echo $row[gender];?>><br>
            年齡 <input type = text name = "age" value = <? echo $row[age];?>><br>
            註冊時間 <input type = text name = "regdate" value = <? echo $row[regdate];?>><br>
            <input type = submit name = ok value = "提交">
            </form>
            <?
  }else
  {
   $sql = "update userinfo set username = '".$_POST[username]."',gender = '".$_POST[gender]."',age = '".$_POST[age]."',regdate = '".$_POST[regdate]."'where id = '".$_POST[id]."'";
   $result = mysql_query($sql);
   if($result)
    echo "記錄已經成功修改<br>"<a href = 'modify.php'>繼續修改記錄</a>;
   else
    echo "記錄修改失敗<br><a href = modify.php?id = ".$_POST[id].">返回</a>";
  }
 }
}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.