日期:2013-04-12  浏览次数:20493 次

登陆页:

<TABLE border="0" width="35%" cellpadding="0" cellspacing="0" align="center">
<FORM METHOD=POST ACTION="checklogin.php">
<TR>
 <TD width="20%">用户名:</TD>
 <TD><INPUT TYPE="text" NAME="username"></TD>
</TR>
<TR>
 <TD>密码:</TD>
 <TD><INPUT TYPE="password" NAME="password"></TD>
</TR>
<TR>
 <TD></TD>
 <TD><INPUT TYPE="submit" value="提交"></TD>
</TR>
</FORM>
</TABLE>

处理页:

<?php
require_once("conn.php");
SESSION_START();
$username=$_POST['username'];
$password=$_POST['password'];
$exec="select * from admin where username='".$username."'";
if ($result=mysql_query($exec)){
 if ($rs=mysql_fetch_object($result)){
  if($rs->password==$password){
   $_SESSION['adminname']=$username;
   echo "SESSION是".$_SESSION['adminname'];
  }else{
   echo "<script>alert('Password Check Error!');location.href('login.htm');</script>";
  }
 }else{
  echo "<script>alert('Username Check Error!');location.href('login.htm');</script>";
 }
}else{
 echo "<script>alert('Database connection Error!');location.href=('login.htm');</script>";
}

?>

数据库驱动;

<?php
$conn = mysql_connect("127.0.0.1","root","");
mysql_select_db("temp",$conn);
?>

摘要:这次主要遇到以下问题:

Session保存路径设置有误,在php.ini文件中设置:session.save_path = D:\usr\local\php\sessiondata,要保证有此目录,

(2004-10-25 11:08:02)   三角猫(50494427)
你在操作数据库的时候, 尽量不要用 mysql_fetch_object  从结果集中取得一行作为对象
(2004-10-25 11:08:58)   三角猫(50494427)
用:mysql_fetch_row  从结果集中取得一行作为枚举数组
mysql_fetch_array 从结果集中取得一行作为关联数组,或数字数组,或二者兼有