求助!php中session验证用户登录出错!~不晓得哪里错了,就是不能登录.求助各位哥哥姐姐们指点指点,在些多谢!~希望加QQ:6021947
建表代码:
CREATE TABLE user(
id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
username VARCHAR(50)NOT NULL,
password VARCHAR(50)NOT NULL,
mail VARCHAR(255),
homepage VARCHAR(255),
leves VARCHAR(10) NOT NULL DEFAULT 'admin',
create_time VARCHAR(19) NOT NULL,
PRIMARY KEY (id));
表里的记录如下:
select * from user;
id username password mail homepage leves create_time
1 ,1 ,1 ,1 ,1, admin ,1
PHP 页面:
<?php
session_start();
include("config.inc.php");
include("dbconnect.inc.php");
if($_GET["do"]=="logout") {
session_unset();
header("Location:index.php");
}
if($_GET["do"] == "1") {
$username = mysql_real_escape_string($_POST["username"]);
$password = $_POST["password"];
$message = "";
if($username == "") {
$message .= "用名不能为空
";
}
if($password == "") {
$message .= "密码不能为空
";
}
if($message == "") {
$sql = "select * from user where username='{$username}' and leves='admin' limit 1";
if($res=mysql_query($sql)) {
$row = mysql_fetch_array($res);
if(md5($password) == $row["password"]) {
$_SESSION["admin"]=1;
$_SESSION["username"]=$username;
header("Location:index.php");
exit;
}
$message = "用户名或密码错误";
}else {
$message = "验证失败,DB错误";
}
}
}
?>
<?php include("header.inc.php"); ?>
<?php include("footer.inc.php");?>