添加页面前端
<?php
session_start();
//先判断是否正常登陆,根据是否有$_session['yhm']
if ($_SESSION['yhm']==null) {
echo "<script>location='denglu.html';</script>";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="css/comm.css">
<link rel="stylesheet" href="css/tianjia.css">
</head>
<body>
<h1>添加学生</h1>
<hr>
<div class="da">
<form action="tianjiaCL.php" method="post" enctype="multipart/form-data">
<div class="hang">
<div class="zuo">学号</div>
<div class="you"> <input type="text" name="xh" id="" class="wbk" required autofocus> </div>
</div>
<div class="hang">
<div class="zuo">姓名</div>
<div class="you"> <input type="text" name="xm" id="" class="wbk" required> </div>
</div>
<div class="hang">
<div class="zuo">性别</div>
<div class="you"> <input type="radio" name="xb" id="" checked
value="男">男 <input
type="radio" name="xb" id="" value="女">女</div>
</div>
<div class="hang">
<div class="zuo">年龄</div>
<div class="you"> <input type="number" name="nl" id="" class="wbk" required> </div>
</div>
<div class="hang">
<div class="zuo">专业</div>
<div class="you">
<select name="zy" id="" class="wbk">
<option value="计算机网络">计算机网络</option>
<option value="计算机软件">计算机软件</option>
<option value="计算机应用">计算机应用</option>
</select>
</div>
</div>
<div class="hang">
<div class="zuo">照片</div>
<div class="you"> <input type="file" name="zhaopian" id="" class="wbk"> </div>
</div>
<div class="hang">
<div class="zuo"></div>
<div class="you"> <input type="submit" value="添加" class="tj"> </div>
</div>
</form>
</div>
</body>
</html>
css文件名:E:\phpstudy_pro\WWW\xsxxgl\xiugai.php
.
.da {
width: 350px;
margin: 100px auto;
background-color: #bee4a8;
padding: 20px;
font-size: 18px;
}
.tj {
border: 1px solid black;
display: inline-block;
width: 60px;
height: 30px;
background-color: #7f945d;
text-align: center;
font-size: 20px;
box-sizing: border-box;
line-height: 30px;
margin-left: 150px;
border-radius: 3px;
cursor: pointer;
}
.zuo,
.you {
float: left;
}
.zuo {
width: 60px;
height: 50px;
}
.hang {
height: 50px;
line-height: 50px;
}
.wbk {
height: 35px;
width: 220px;
font-size: 16px;
padding-left: 20px;
border-radius: 5px;
}
a {
cursor: default;
}
h1 {
text-align: center;
margin-top: 50px;
font-weight: 500;
}
hr {
height: 2px;
background-color: #a9d311;
}
添加记录后端
文件名:E:\phpstudy_pro\WWW\xsxxgl\tianjiaCL.php
<?php
session_start();
//先判断是否正常登陆,根据是否有$_session['yhm']
if ($_SESSION['yhm']==null) {
echo "<script>location='denglu.html';</script>";
}
$xuehao=$_POST['xh'];
// echo $xuehao;
$xingmin=$_POST['xm'];
// echo $xingmin;
$xingbie=$_POST['xb'];
// echo $xingbie;
$nianlin=$_POST['nl'];
// echo $nianlin;
$zhuanye=$_POST['zy'];
// echo $zhuanye;
$zhaopian=$_FILES['zhaopian'];
// var_dump($zhaopian);
move_uploaded_file($zhaopian['tmp_name'],'imgs\\'.$zhaopian['name']);//保存文件
$sql="insert into xsb values(null,'{$xuehao}','{$xingmin}','{$xingbie}','{$nianlin}','{$zhuanye}','".$zhaopian['name']."')";
echo $sql;
$pdo=new PDO('mysql:dbname=mydb;host=localhost','root','123456');
$n=$pdo->exec($sql);
if($n==1){
echo "<script>alert('添加学生成功!');location='zhuye.php';</script>";
}else{
echo "<script>alert('添加学生失败!');location='tianjia.php';</script>";
}
发表评论 取消回复