注册页前端
文件名:E:\phpstudy_pro\WWW\xsxxgl\zhuce.php
<!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/zhuce.css">
</head>
<body>
<h1>学生信息管理系统</h1>
<hr>
<div class="da">
<form action="zhucechuli.php" method="post">
<div class="hang">
<div class="zuo">用户名</div>
<div class="you"><input type="text" name="yhm" id="" class="wbk"></div>
</div>
<div class="hang">
<div class="zuo">密 码</div>
<div class="you"><input type="password" name="mm" id="" class="wbk"></div>
</div>
<div class="hang">
<div class="zuo"> </div>
<div class="you"> <input type="submit" value="注册" class="zc"></div>
</div>
</form>
</div>
</body>
</html>
注册页css文件 E:\phpstudy_pro\WWW\xsxxgl\css\zhuce.css
.da {
width: 350px;
margin: 100px auto;
background-color: #bee4a8;
padding: 20px;
}
.zc {
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;
font-size: 18px;
}
.hang {
height: 50px;
line-height: 50px;
}
.wbk {
height: 35px;
width: 220px;
font-size: 16px;
padding-left: 20px;
border-radius: 5px;
}
h1 {
text-align: center;
margin-top: 50px;
font-weight: 500;
}
hr {
height: 2px;
background-color: #a9d311;
}
注册页后端
文件名:E:\phpstudy_pro\WWW\xsxxgl\zhucechuli.php
<?php
$yhm=$_POST['yhm'];
$mm=$_POST['mm'];
// echo $yhm,$mm;
// if用户名不存在,将注册的用户名密码写入数据库
$sql="select count(*) from yhb where yhm='{$yhm}'";
$pdo=new PDO('mysql:dbname=mydb;host=localhost','root','123456');
// $n=$pdo->query($sql)->fetchAll()[0][0];
$jieguo=$pdo->query($sql);
$arr=$jieguo->fetchAll();
$n=$arr[0][0];
echo $n;
if ($n==0) {
//可以注册,注册成功,返回登录页
$sql="insert into yhb values(null,'{$yhm}','{$mm}')";
$m=$pdo->exec($sql);
if($m==1){
echo "<script>alert('注册成功!');location='denglu.html';</script>";
}else{
echo "<script>alert('注册失败!');location='zhuce.php';</script>";
}
}else{
//用户名已经存在,不能注册,返回注册页
echo "<script>alert('用户名已经存在!');location='zhuce.php';</script>";
}