PHP数据库增删改查

不言
发布: 2018-04-14 10:44:42
原创
2171人浏览过

本篇文章给大家分享的内容是PHP数据库增删改查 ,有着一定的参考价值,有需要的朋友可以参考一下

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

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会话 

 

图改改
图改改

在线修改图片文字

图改改455
查看详情 图改改

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

相关标签:
php
PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

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

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号