PHP資料庫增刪改查

不言
發布: 2023-03-23 19:48:02
原創
1908 人瀏覽過

這篇文章給大家分享的內容是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[&#39;txtName&#39;];
$age = $_POST[&#39;txtAge&#39;];
$gender = $_POST[&#39;rdGender&#39;];
 
$db =mysqli_connect("localhost","root","1234");
mysqli_select_db($db,"studentdb");
 
$in="insert intostudentinfotbl(stuName,stuAge,stuGender)values(&#39;$name&#39;,&#39;$age&#39;,&#39;$gender&#39;)";
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>
<?php
while($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 = &#39;delete_2018411.php?id=$resArry[0]&#39;> delete</a>";  ?></td>
         <td><?phpecho "<a href = &#39;updateFirst.php?id=$resArry[0]&#39;> update</a>";  ?></td>
</tr>
 
<?php
}
?>
 
</table>
 
 
 
 
 
 
 
 
delete_2018411.php
 
<?php
 
$db = mysqli_connect("localhost","root","1234");
mysqli_select_db($db,"studentdb");
 
$id = $_GET[&#39;id&#39;];
$delete = "delete from studentinfotblwhere stuId = $id";
mysqli_query($db,$delete);
 
header("location:show_2018411.php");
 
?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
updateFirst.php
 
<?php
session_start();
$id = $_GET[&#39;id&#39;];
echo $id;
$_SESSION[&#39;id&#39;]=$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
<?php
session_start();
 
$db = mysqli_connect("localhost","root","1234");
mysqli_select_db($db,"studentdb");
 
$name = $_POST[&#39;txtName&#39;];
$age = $_POST[&#39;txtAge&#39;];
$gender = $_POST[&#39;rdGender&#39;];
 
$id = $_SESSION[&#39;id&#39;];
 
if(1){
         $update= "update  studentinfotbl setstuName = &#39;$name&#39;,stuAge = $age,stuGender = $gender
         wherestuId =$id;";
         mysqli_query($db,$update);
        
}
 
session_destroy();
 
header("location:show_2018411.php");
 
?>
登入後複製

相關推薦:

PHP資料庫保存session會話 


 


#

以上是PHP資料庫增刪改查的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
作者最新文章
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!