Heim  >  Artikel  >  Backend-Entwicklung  >  php mysq数据编辑更新实例_PHP教程

php mysq数据编辑更新实例_PHP教程

WBOY
WBOYOriginal
2016-07-13 17:05:08800Durchsuche

php mysq数据编辑更新实例 /* 本文章是也一款入门级php教程了,主要是告诉你如何利用php mysq数据编辑更新哦。

php教程 mysq数据编辑更新实例
/*
本文章是也一款入门级php教程了,主要是告诉你如何利用php mysq数据编辑更新哦。
*/

$db = mysql教程_connect("localhost", "phpdb", "phpdb");
mysql_select_db("test",$db);

// 如果提交了submit按钮
if ($submit) {  
   // 如果没有id,则是在增加记录,否则是在修改记录
   if ($id) {
     $sql = "update employees set first='$first',last='$last',     address='$address',position='$position' where id=$id";
   }
   else {
     $sql = "insert into employees (first,last,address,position) values ('$first','$last','$address','$position')";
   }  
   // 向数据库教程发出sql命令
   $result = mysql_query($sql);
   echo "记录修改成功!";
   echo "返回";
}
elseif ($delete) {
 // 删除一条记录
     $sql = "delete from employees where id=$id";
     $result = mysql_query($sql);
     echo "记录删除成功!";
  echo "返回";
}
else {  
   // 如果还没有按submit按钮,那么执行下面这部分程序
   if (!$id) {    
     // 如果不是修改状态,则显示员工列表
     $result = mysql_query("select * from employees",$db);
     while ($myrow = mysql_fetch_array($result)) {
       printf("%s %s n",
        $php_self, $myrow["id"], $myrow["first"], $myrow["last"]);
    printf("(delete)
",  $php_self, $myrow["id"]);
     }
}
?>
   返回
  


      if ($id) {
     // 是在编辑修改状态,因些选择一条记录
     $sql = "select * from employees where id=$id";
     $result = mysql_query($sql);
     $myrow = mysql_fetch_array($result);
     $id = $myrow["id"];
     $first = $myrow["first"];
     $last = $myrow["last"];
     $address = $myrow["address"];
     $position = $myrow["position"];
     // 显示id,供用户编辑修改
     ?>
    
        }
   ?>
   名:
   姓:
  

   住址:
   职位:
  

  
  

}
?>
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn