写了注册页面但是登录失败,该怎么处理
程序员文章站
2022-04-29 14:58:30
...
写了注册页面但是登录失败
注册代码:
include("config.php");
include("conn.php");
if($_POST['submit']){
$pass=md5($_POST[password].all_ps);
$sql = "insert into user (uid,m_id,username,password) " .
"values ('','','{$_POST['username']}','$pass')";
mysql_query($sql);
echo "";
}
?>
登录代码:
include ("config.php");
include("conn.php");
if($_POST[submit]){
$username= str_replace(" ","",$_POST[username]);
$sql="select * from user where 'username' = '$username'";
$query=mysql_query($sql);
$us=is_array($row=mysql_fetch_array($query));
$ps= $us ? md5($_POST[password].all_ps)== $row[password] : FALSE;
if($ps){
$_SESSION[uid]=$row[uid];
$_SESSION[user_shell]=md5($row[username].$row[password].all_ps);
echo"登陆成功";
}else{
echo "用户名密码错误";
}
}
?>
password是经过md5加一个常量all_ps加密过的,登录页面总是显示登录失败
------解决方案--------------------
做一个输出
echo md5($_POST[password].all_ps);
echo $row[password];
看一看是否一致。
注册代码:
include("config.php");
include("conn.php");
if($_POST['submit']){
$pass=md5($_POST[password].all_ps);
$sql = "insert into user (uid,m_id,username,password) " .
"values ('','','{$_POST['username']}','$pass')";
mysql_query($sql);
echo "";
}
?>
登录代码:
include ("config.php");
include("conn.php");
if($_POST[submit]){
$username= str_replace(" ","",$_POST[username]);
$sql="select * from user where 'username' = '$username'";
$query=mysql_query($sql);
$us=is_array($row=mysql_fetch_array($query));
$ps= $us ? md5($_POST[password].all_ps)== $row[password] : FALSE;
if($ps){
$_SESSION[uid]=$row[uid];
$_SESSION[user_shell]=md5($row[username].$row[password].all_ps);
echo"登陆成功";
}else{
echo "用户名密码错误";
}
}
?>
password是经过md5加一个常量all_ps加密过的,登录页面总是显示登录失败
------解决方案--------------------
做一个输出
echo md5($_POST[password].all_ps);
echo $row[password];
看一看是否一致。
相关文章
相关视频