Home > Backend Development > PHP Tutorial > Basic operation code for adding, modifying and deleting database (1/4)_PHP tutorial

Basic operation code for adding, modifying and deleting database (1/4)_PHP tutorial

WBOY
Release: 2016-07-13 17:04:42
Original
1046 people have browsed it

Basic operation codes for database addition, modification, and deletion This is a tutorial that is more suitable for PHP beginners. We use a simple example to add, modify, and delete the database, so that you can know the key points of PHP mysql database operations in a more systematic way.

Database tutorial to add, modify and delete basic operation codes
This is a tutorial that is more suitable for beginners to learn PHP tutorials. We use a simple example to add, modify, and delete the database, so that you can know the key points of database operations in the PHP mysql tutorial in a more systematic way.
*/
require_once('common.php');
$action = $_get['action'];
?>





人才列表


 
 


 

        if($action=='add'){
 ?>
   

 
         
           
         
           
         
         
           
           
         
         
           
           
         
          
           
           
         
           
             
           
             
     
添加人员
登陆账号
登陆密码
问题
答案

   

        }
      elseif($action=='save'){
    $login = isset($_post['login']) ? $_post['login'] : '';
    $pws = isset($_post['pws']) ? $_post['pws'] : '';
    $question = isset($_post['question']) ? $_post['question'] : '';
    $answer = isset($_post['answer']) ? $_post['answer'] : '';
    $sql = "insert into person (login,pws,question,answer)
    values('$login','$pws','$question','$answer')";
    $db->query($sql);
    forward('发布成功','href','personlist.php');
          }

    elseif($action=='del'){
    $person_id=$_get['person_id'];
    $page=$_get['page'];
    $sql="delete from person where person_id='$person_id'";
    $db->query($sql);
    forward('删除成功','href','personlist.php?page='.$page);
          } 
    elseif($action=='editsave'){
    $person_id = isset($_post['person_id']) ? $_post['person_id'] : '';
    $page = isset($_post['page']) ? $_post['page'] : '';
          $login = isset($_post['login']) ? $_post['login'] : '';
    $pws = isset($_post['pws']) ? $_post['pws'] : '';
    $question = isset($_post['question']) ? $_post['question'] : '';
    $answer = isset($_post['answer']) ? $_post['answer'] : '';
    $sql="update person set login='$login',pws='$pws',question='$question',answer='$answer' where person_id='$person_id'";
    $db->query($sql);
          forward('修改成功','href','personlist.php?page='.$page);
          }
   elseif($action=='edit'){
    $person_id=$_get['person_id'];
    $page=$_get['page'];
    $sql="select * from person where person_id='$person_id'";
    $query = $db->query($sql);
    $row = $db->fetch_array($query);
    $login=$row['login'];
    $pws=$row['pws'];
    $question=$row['question'];
    $answer=$row['answer'];
       ?>
   


 
         
         
         
           
         
           
         
         
           
           
         
         
           
           
         
          
           
           
         
           
             
           
             
     
修改人员
登陆账号
登陆密码
问题
答案

   

            }
      else{
          $page = isset($_get['page']) ?intval($_get['page']) : 1;
          $num = 5;
          $sql="select * from person";
          $query = $db->query($sql);
          $totalnum = $db->num_rows($query);//记录总数
          $pagenum = ceil($totalnum/$num); //总页数
          $offset = ($page-1) * $num;
          $sql=$sql." limit $offset,$num ";
          $query = $db->query($sql);//取得记录
        ?>
         
         
           
         
         
         
         
         
         
         
           while ($row = $db->fetch_array($query)) {
        ?>
         
         
           
           
           
           
           
         
                                                                                    }
          ?>
记录总数:————添加人员
登陆账号登陆密码问题答案加入时间操作
删除/
            修改


        

                   


}
?>



1 2 3 4

http://www.bkjia.com/PHPjc/630832.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/630832.htmlTechArticleBasic operation code for database addition, modification, and deletion. This is a tutorial that is more suitable for PHP beginners. We Use a simple example to add, modify, and delete the database...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template