3.5、后端开发基础php(下) <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta charset="utf-8"> <title>登录</title> </head> <body> <form method="post" action="login.php"> <div> <div style="height: 30px"> <span>账号</span> <input name="username" type="text" /> </div> <div style="height: 30px"> <span>密码</span> <input name="password" type="password" /> </div> <div style="height: 30px;"> <input type="submit" value="登录" /> </div> </div> </form> </body> </html>
<?php $dbname="testdb"; $conn=mysqli_connect("localhost","root","root",$dbname);//链接数据库 if(!$conn) { echo "数据库连接错误!"; return; } $username=""; $password=""; //验证用户名密码 if(empty($_POST['username'])){ echo "用户名不能为空"; return; } else if(empty($_POST['password'])){ echo "密码不能为空"; return; }else{ //过滤单引号 $username=str_replace("'","‘",$_POST['username']); $password=str_replace("'","‘",$_POST['password']); } //判断用户是否存在 $strsql="select 1 from admin where username='" . $username . "'" ; $result=mysqli_query($conn,$strsql); $rows=mysqli_num_rows($result); if($rows) { //判断用户名密码是否正确 $strsq2="select 1 from admin where username='" . $username . "' and password = '" . $password . "'"; $result2=mysqli_query($conn,$strsq2); $rows2=mysqli_num_rows($result2); if($rows2) { echo "登录成功!"; } else { echo "密码不正确!"; } } else { echo "用户名不存在"; } ?>
打赏我,让我更有动力~
© 2016 - 2024 掌控者 All Rights Reserved.
Track-方丈
发表于 2018-7-12
通过,金币奖励已发放。
评论列表
加载数据中...