PHP数据库增删改查

不言
Lepaskan: 2023-03-23 19:48:02
asal
1921 orang telah melayarinya

本篇文章给大家分享的内容是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");
 
?>
Salin selepas log masuk

相关推荐:

PHP数据库保存session会话 


 


Atas ialah kandungan terperinci PHP数据库增删改查. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Artikel terbaru oleh pengarang
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan