写了注册页面但是登录失败
注册代码:
<?php
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 "<script language=\"javascript\">alert('注册成功');history.go(-1)</script>";
}
?>
登录代码:
<?php
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];
看一看是否一致。