PHP資料庫增刪改查

來源:互聯網
上載者:User
本篇文章給大家分享的內容是PHP資料庫增刪改查 ,有著一定的參考價值,有需要的朋友可以參考一下

Register_2018411.php <body> <form name = "frm" action ="insert_2018411.php" method = "post"> Name<input type = "text" name= "txtName"/><br/>Age<input type = "text" name ="txtAge"/><br/> Gender<input type = "radio" name ="rdGender" value = "1">Male<input type = "radio" name ="rdGender" value = "0">Female<br/> <input type = "submit" name ="sbtsubmit" value = "Register"/> </form></body>   insert_2018411.php <?php $name = $_POST['txtName'];$age = $_POST['txtAge'];$gender = $_POST['rdGender']; $db =mysqli_connect("localhost","root","1234");mysqli_select_db($db,"studentdb"); $in="insert intostudentinfotbl(stuName,stuAge,stuGender)values('$name','$age','$gender')";mysqli_query($db,$in); header("location:show_2018411.php");?>     show_2018411.php <?php$db =mysqli_connect("localhost","root","1234");mysqli_select_db($db,"studentdb"); $select = "select * fromstudentinfotbl";$result = mysqli_query($db,$select); ?> <table border = 1><tr><td>stuName</td><td>stuAge</td><td>stuGender</td><td>delete</td><td>update</td></tr><?phpwhile($resArry=mysqli_fetch_array($result)){?><tr>         <td><?phpecho $resArry[1]; ?></td>         <td><?phpecho $resArry[2]; ?></td>         <td><?php                  if($resArry[3]==1){                          echo"男";                  }else{                          echo"女";                  }         ?></td>                 <td><?phpecho "<a href = 'delete_2018411.php?id=$resArry[0]'> delete</a>";  ?></td>         <td><?phpecho "<a href = 'updateFirst.php?id=$resArry[0]'> update</a>";  ?></td></tr> <?php}?> </table>        delete_2018411.php <?php $db = mysqli_connect("localhost","root","1234");mysqli_select_db($db,"studentdb"); $id = $_GET['id'];$delete = "delete from studentinfotblwhere stuId = $id";mysqli_query($db,$delete); header("location:show_2018411.php"); ?>              updateFirst.php <?phpsession_start();$id = $_GET['id'];echo $id;$_SESSION['id']=$id; ?> <body><form name = "frm" action ="update_2018411.php" method = "post"> Name<input type = "text" name= "txtName"/><br/>Age<input type = "text" name ="txtAge"/><br/> Gender<input type = "radio" name ="rdGender" value = "1">Male<input type = "radio" name ="rdGender" value = "0">Female<br/> <input type = "submit" name ="sbtsubmit" value = "OK"/> </form></body>    update_2018411.php<?phpsession_start(); $db = mysqli_connect("localhost","root","1234");mysqli_select_db($db,"studentdb"); $name = $_POST['txtName'];$age = $_POST['txtAge'];$gender = $_POST['rdGender']; $id = $_SESSION['id']; if(1){         $update= "update  studentinfotbl setstuName = '$name',stuAge = $age,stuGender = $gender         wherestuId =$id;";         mysqli_query($db,$update);        } session_destroy(); header("location:show_2018411.php"); ?>

聯繫我們

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