环境是用phpstudy_pro这个,软件是用的phpstorm,数据库是localhost的
点登录后,显示: 登录失败
<?php
header("Content-Type:text/html;charset=utf-8");
$username = trim($_POST['username']);
$pw = trim($_POST['pw']);
//进行必要的验证
if (!strlen($username) || !strlen($pw) ){
echo"<script>alert('用户名和密码都必须要填写');history.back();</script>";
exit;
}else {
if (!preg_match('/^[a-zA-Z0-9]{3,10}$/', $username)) {
echo "<script>alert('用户名必填,且只能由大小字符和数字构成,长度为3到10个字符!');history.back();</script>";
exit;
}
if (!preg_match('/^[a-zA-Z0-9_*]{6,10}$/', $pw)) {
echo "<script>alert('密码必填,且只能大小写字符和数字,以及*、_构成,长度为6-10个字符!');history.back();</script>";
exit;
}
}
//连接数据库
//第一步,连接到数据库
$conn = mysqli_connect("localhost","root","20031022","member");
//第二步,设置字符串
mysqli_query($conn,"set names utf8");
$sql = "select * from info where username = '".$username."' and pw ='“.md5($pw).“'";
$result = mysqli_query($conn,$sql);
$num = mysqli_num_rows($result);
if($num){
echo "<script>alert('登录成功!')</script>";
}else{
echo "<script>alert('登录失败!');history.back();</script>";
}