文件名称:login.php
html代码
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <link rel="stylesheet" type="text/css" href="http://www.niuguwen.com/plugin/niuguwen/css/niuguwen.css"> <title>用户登录</title> </head> <body> <div class="ngwlogin"> <div class="formtitle"> <a href="/">人才管理系统</a> </div> <div class="ngwform formbody"> <form class="form" action="login.php" method="post"> <div> <label>用户名</label> <input type="text" name="username" placeholder="请输入用户名(学号或手机号)" required="required" class="input" value="" /> </div> <div> <label>密码</label> <input type="password" name="password" placeholder="请输入密码" required="required" class="input" value="" /> </div> <ul> <li class="fl"><button type="submit">登录</button></li> <li class="fr"> <a href="register.php">注册</a> </li> </ul> </form> </div> <div class="formfoot"></div> </div>
login.php文件完整源代码
<?php
if($_POST['username']&&$_POST['psd']){
$conn=@mysqli_connect("localhost","root","root","rencai") or die("无法连接数据库");
$sql="select * from user where username='".$_POST['username']."' and psd='".$_POST['psd']."'";
$result=mysqli_query($conn,$sql);
$row=mysqli_fetch_array($result);
if($row['username']){
echo "登录成功";
}else{
echo "登录失败";
}
}else{
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="http://www.niuguwen.com/plugin/niuguwen/css/niuguwen.css">
<title>用户登录</title>
</head>
<body>
<div class="ngwlogin">
<div class="formtitle">
<a href="/">人才管理系统</a>
</div>
<div class="ngwform formbody">
<form class="form" action="login.php" method="post">
<div>
<label>用户名</label>
<input type="text" name="username" placeholder="请输入用户名(学号或手机号)" required="required" class="input" value="" />
</div>
<div>
<label>密码</label>
<input type="password" name="psd" placeholder="请输入密码" required="required" class="input" value="" />
</div>
<ul>
<li class="fl"><button type="submit">登录</button></li>
<li class="fr">
<a href="register.php">注册</a>
</li>
</ul>
</form>
</div>
<div class="formfoot"></div>
</div>
</body>
</html>
<?php
}?>- 文章导航