-1

每次登录时,密码都会从数据库中删除。其余数据完好无损。我是网络编程的初学者,对此我一无所知。这可能是什么原因?

[从评论中复制的代码]

$user= $_POST['username']; 
$pass = $_POST['password']; 
if((isset($user))&&(isset($pass))) { 
  $query ="Select password from table1 where user_name='".$user."'"; 
  $result = mysql_query($query) or die(); 
  $r= mysql_fetch_assoc($result) or die(); 

  if(!strcmp($pass, $r)) { 
   echo "succesful"; 
   session_start(); 
   $_SESSION['username']=$user; 
   $_SESSION['logged']=1; 
   header("Refresh: 0; URL = ..\home\index.php"); 
  } 
}
4

1 回答 1

0

session_start检查 isset($_POST['username']) 时,您需要在第一行执行

session_start(); 
$user= isset($_POST['username']) ? trim($_POST['username']) : false; 
$password = isset($_POST['password']) ? trim($_POST['password']) : false; 

if($user !== false && $password !== false) {

当您正确执行此操作时:

$r= mysql_fetch_assoc($result) or die(); 
if(!strcmp($pass, $r['password'])) { 

和标题:

header("Location: ..\home\index.php"); 
于 2012-05-23T05:42:54.820 回答