PHP数据库增删改查

不言
发布: 2023-03-23 19:48:02
原创
1924 人浏览过

本篇文章给大家分享的内容是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
作者最新文章
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板