student

head.html

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		<ul>
			<li><a href="add.php">增加</a></li>
			<li><a href="show.php">删除</a></li>
			<li><a href="show.php">修改</a></li>
			<li><a href="show.php">查询</a></li>
		</ul>
	</body>
</html>

add.php

<?php
	require_once("head.html");
	require_once("dbop.php");
?>
<?php
	if(isset($_GET['stuid'])){
		require('check.php');
		$vail = check();
		if($vail){
			$sql="INSERT INTO student (`stuid`,`name`,`sex`,`class`,`tel`)".
			"VALUES('{$_GET['stuid']}','{$_GET['name']}','{$_GET['sex']}','{$_GET['class']}','{$_GET['tel']}')";
			if(query($sql)==true){
				echo "增加成功";
			}else{
				echo "增加失败";
			}
		}else{
			echo "格式错误";
		}
	}
?>
<form action="add.php" method="get">
	<label>学号</label>
	<input type="text" name="stuid" id="" /><br />
	<label>姓名</label>
	<input type="text" name="name" id="name" value="" /><br />
	<label>性别</label>
	<input type="text" name="sex" id="" /><br />
	<label>班级</label>
	<input type="text" name="class" id="" /><br />
	<label>电话</label>
	<input type="text" name="tel" id="" /><br />
	<input type="submit" value="新增加" />
	
</form>

check.php

<?php
	function check(){
		$arr = str_split($_GET['tel']);
		foreach($arr as $a){
			if($a<'0'||$a>'9'){
				return false;
			}
		}
		$sql = "select count(stuid) from student where stuid='{$_GET['stuid']}' ";
		$ans=query($sql);
		$cnts=$ans->fetch_array();
		if($cnts[0]!=0){
			return false;
		}
		return true;
	}
?>

dbop.php

<?php
	function query($sql){
		$db=new mysqli("localhost","root","","dome");
		$db->query("set names utf8");
		$ret = $db->query($sql);
		$db->close();
		return $ret;
	}
?>

del.php

<?php
	require_once("dbop.php");
?>
<?php
	$did = $_GET['id'];
	echo $did;
	$sql="delete from `student` where `id`='$did' ";
	echo $sql;
	query($sql);
	header("Location:show.php");
?>

show.php

<?php
	//查询并显示所有学生的信息
	require_once("head.html");
	require_once("dbop.php");
?>
<?php
	$sql="select * from student";
	$ans=query($sql);
?>
<table border="1px solid black ">
	<tr>
		<th>数据库id</th>
		<th>学号</th>
		<th>姓名</th>
		<th>性别</th>
		<th>班级</th>
		<th>电话</th>
		<th>功能</th>
	</tr>
	<?php
		while($ro=mysqli_fetch_array($ans)){
	?>	
	<tr>
		<td><?php echo $ro['id'];?></td>
		<td><?php echo $ro['stuid'];?></td>
		<td><?php echo $ro['name'];?></td>
		<td><?php echo $ro['sex'];?></td>
		<td><?php echo $ro['class'];?></td>
		<td><?php echo $ro['tel'];?></td>
		<td><a href="del.php?id=<?php echo $ro['id']; ?>" style="color: #1C86EE;">删除</a>
			<a href="update.php?id=<?php echo $ro['id']; ?>" style="color: #1C86EE;">修改</a></td>
	</tr>
	<?php } ?>
</table>

up.php

<?php
	require_once("dbop.php");
	$id=$_GET['id'];
	$stuid=$_POST['stuid'];
	$name=$_POST['name'];
	$sex=$_POST['sex'];
	$class=$_POST['class'];
	$tel=$_POST['tel'];
?>
<?php
	$sql="update student set stuid='".$stuid."',name='".$name."',sex='".$sex."',class='".$class."',tel='".$tel.
	"' WHERE id='".$id."'";
//	echo $sql;
	if(query($sql)){
		echo "修改成功";
	}else{
		echo "修改失败";
	}
	header("Location:show.php");
?>

update.php

<?php
	require_once("head.html");
	require_once("dbop.php");
	require('check.php');
	$id=$_GET['id'];
	$sql="SELECT * FROM student WHERE id='".$id."'";
	$ans=query($sql);
	if($ro=mysqli_fetch_array($ans)){
?>
<form action="up.php?id=<?php echo $id;?> " method="post">
	<label>数据库id</label>
	<input type="text" name="id" id="id" value="<?php echo $id;?>" disabled="disabled" /><br />
	<label>学号</label>
	<input type="text" name="stuid" id="" value="<?php echo $ro['stuid'];?>"/><br />
	<label>姓名</label>
	<input type="text" name="name" id="name" value="<?php echo $ro['name'];?>" /><br />
	<label>性别</label>
	<input type="text" name="sex" id="" value="<?php echo $ro['sex'];?>"/><br />
	<label>班级</label>
	<input type="text" name="class" id="" value="<?php echo $ro['class'];?>"/><br />
	<label>电话</label>
	<input type="text" name="tel" id="" value="<?php echo $ro['tel'];?>"/><br />
	<input type="submit" value="修改" />
</form>
<?php }?>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值