zhuce.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>注册</title>
</head>
<body>
<form action="zhuce_in.php" method="post" onsubmit="return tijiao(this)">
用户名:<input type="text" name="username" value="">*
<br>
密码:<input type="password" name="password" value="">*
<br>
性别:<input type="radio" name="sex" value="男">男
<input type="radio" name="sex" value="女">女
<br>
<br>
爱好:<br>
<input type="checkbox" name="hobby[]" value="游泳">游泳<br>
<input type="checkbox" name="hobby[]" value="读书">读书<br>
<input type="checkbox" name="hobby[]" value="健身">健身<br>
<input type="checkbox" name="hobby[]" value="timi">timi<br>
城市:<br>
<select name="city">
<option selected disabled>请选择</option>
<option>烟台</option>
<option>菏泽</option>
<option>淄博</option>
<option>潍坊</option>
<option>济宁</option>
<option>枣庄</option>
<option>滨州</option>
</select>
<br><br>
<input type="submit" value="注册">
</form>
带*必须填写!
<script>
function tijiao(form){
if(form.username.value=='')
{
alert('请输入用户名!');
return false;
}
if(form.password.value=='')
{
alert('请输入密码!');
return false;
}
}
</script>
</body>
</html>
复制
zhuce_in.php
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>注册页面</title>
</head>
<body>
<?php
$name=$_POST['username'];
$password=$_POST['password'];
$sex=$_POST['sex'];
$hobby=$_POST['hobby'];
$city=$_POST['city'];
$hobbies='';
foreach($hobby as $a)
$link=mysqli_connect("localhost","root","","stu_info");
mysqli_set_charset($link,'utf8');
$sql = "insert into user (id,name,password,sex,hobby,city)values(null,'$name','$password','$sex','$hobbies','$city')";
mysqli_query($link,$sql);
header('location:zhuce.php');
?>
</table>
</body>
</html>
复制
list.php
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>用户信息打印页面</title>
</head>
<body>
<?php
$link=mysqli_connect("localhost","root","","stu_info");
mysqli_set_charset($link,'utf8');
$rel = mysqli_query($link,'select * from user');
?>
<h1 align=center>用户信息</h1>
<a href="./zhuce.php">添加信息</a>
<table align=center border=1px cellspacing=0 cellpadding=0>
<tr>
<th>id</th>
<th>name</th>
<th>password</th>
<th>sex</th>
<th>hobby</th>
<th>city</th>
<th>change</th>
</tr>
<?php
while($result = mysqli_fetch_array($rel) )
{
echo '<tr><td>'.$result['0'].'</td>';
echo '<td>'.$result['1'].'</td>';
echo '<td>'.$result['2'].'</td>';
echo '<td>'.$result['3'].'</td>';
echo '<td>'.$result['4'].'</td>';
echo '<td>'.$result['5'].'</td>';
echo "<td> <a href='delete.php?id=$result[0] '>";
echo '删除';
echo '</a>';
echo ' '."<a href='up.php?id=$result[0] '>"."修改"."</a>";
echo ' </td>';
echo '</tr>';
}
?>
</table>
</body>
</html>
复制
delete.php
<?php
$id = $_GET['id'];
$link = mysqli_connect('localhost','root','','stu_info');
mysqli_set_charset($link,'utf8');
$sql = "delete from user where id=$id";
$a = mysqli_query($link,$sql);
header('location:list.php');
?>
复制
up.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<?php
$id = $_GET['id'];
$link = mysqli_connect('localhost','root','','stu_info');
mysqli_set_charset($link,'utf8');
$sql = "select * from user where id=$id";
$res = mysqli_query($link,$sql);
$rows = mysqli_fetch_array($res);
echo '序号:'.$rows[0];
?>
<form action="update.php" method="post">
<input type="hidden" name="id" value="<?php echo $rows[0]; ?>"><br>
姓名:<input type="text" name="name" value="<?php echo $rows[1]; ?>"><br>
密码:<input type="text" name="password" value="<?php echo $rows[2]; ?>"><br>
<?if($rows[3] == '男'){?>
<input type="radio" name="sex" value="男" checked="checked">男
<input type="radio" name="sex" value="女">女<br>
<?} else { ?>
<input type="radio" name="sex" value="男">男
<input type="radio" name="sex" value="女" checked="checked">女<br>
<?}?>
爱好:<input type="text" name="hobby" value="<?php echo $rows[4]; ?>"><br>
城市:<input type="text" name="city" value="<?=$rows[5] ?>"><br>
<input type="submit" value="修改" >
</form>
</body>
</html>
复制
update.php
<?php
$id = $_POST['id'];
$name = $_POST['name'];
$password = $_POST['password'];
$sex = $_POST['sex'];
$hobby = $_POST['hobby'];
$city = $_POST['city'];
$link = mysqli_connect('localhost','root','','stu_info');
mysqli_set_charset($link,'utf8');
$sql = "update user set name = '$name',password = '$password',sex = '$sex',hobby = '$hobby',city = '$city' where id = $id";
mysqli_query($link,$sql);
header('location:list.php');
?>
复制
@阿帆fan
相关推荐:
文章转载自阿帆fan,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
评论
相关阅读
【MySQL 30周年庆】MySQL 8.0 OCP考试限时免费!教你免费领考券
墨天轮小教习
2874次阅读
2025-04-25 18:53:11
MySQL 30 周年庆!MySQL 8.4 认证免费考!这次是认真的。。。
严少安
838次阅读
2025-04-25 15:30:58
【活动】分享你的压箱底干货文档,三篇解锁进阶奖励!
墨天轮编辑部
487次阅读
2025-04-17 17:02:24
MySQL 9.3 正式 GA,我却大失所望,新特性亮点与隐忧并存?
JiekeXu
424次阅读
2025-04-15 23:49:58
3月“墨力原创作者计划”获奖名单公布
墨天轮编辑部
371次阅读
2025-04-15 14:48:05
记录MySQL数据库的一些奇怪的迁移需求!
陈举超
274次阅读
2025-04-15 15:27:53
MySQL 8.0 OCP 1Z0-908 考试解析指南(二)
JiekeXu
272次阅读
2025-04-30 17:37:37
SQL优化 - explain查看SQL执行计划(下)
金同学
261次阅读
2025-05-06 14:40:00
MySQL 8.0 OCP 1Z0-908 考试题解析指南
青年数据库学习互助会
241次阅读
2025-04-30 12:17:54
MySQL 8.4 新特性深度解析:功能增强、废弃项与移除项全指南
JiekeXu
226次阅读
2025-04-18 20:21:32