登录  /  注册
PHP数据库增删改查
不言
发布: 2023-03-23 19:48:02
原创
1441人浏览过

本篇文章给大家分享的内容是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>
<?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 = '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
 
<?php
session_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
<?php
session_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");
 
?>
登录后复制

相关推荐:

PHP数据库保存session会话



以上就是PHP数据库增删改查的详细内容,更多请关注php中文网其它相关文章!

相关标签:
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 技术文章
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2023 //m.sbmmt.com/ All Rights Reserved | 苏州跃动光标网络科技有限公司 | 苏ICP备2020058653号-1

 | 本站CDN由 数掘科技 提供

登录PHP中文网,和优秀的人一起学习!
全站2000+教程免费学