即使输入正确的值后也不能登录 [英] login not possible even after putting in the correct values
问题描述
可能重复:
未定义索引:C:\wamp\www\Website\storeadmin\admin_login.php..中的用户名密码
//admin_login.php
<?php
session_start();
if(isset($_SESSION["member"])){
header("location:index.php");
exit();
}
?>
<?php
if(isset($_POST["username"]) && isset($_POST["password"])){ // <- Check the user has clicked the button
$manager = preg_replace('#[A-Za-z0-9]#i',"",$_POST["username"]);
$password = preg_replace('#[A-Za-z0-9]#i',"",$_POST["password"]);
include "../storescripts/connect_to_mysql.php";
$sql = mysql_query("SELECT * FROM admin WHERE username ='$manager' AND password ='$password'LIMIT 1");
$exist_count = mysql_num_rows($sql);
if($exist_count == 1){
while(mysql_fetch_array($sql)){
$id = $row["id"];
}
$_SESSION["id"]= $id;
$_SESSION["manager"]= $manager;
$_SESSION["password"]= $password;
header("location:index.php");
exit();
}
else{
echo 'This information is incorrect,try again <a href = "index.php">Click Here</a>';
exit();
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> AdminLogin</title>
<link rel="stylesheet" href="../style/style.css" type="text/css" media="screen"/>
</head>
<body>
<div id="mainWrapper" >
<?php include_once("../template_header.php");?>
<div id="pageContent" >
<div align="left" "style="margin-left:040px;"><h1>Please login to continue</h1><br />
</div>
<form id="form1" name="form1" method="post" action="admin_login.php">
UserName<br />
<input type="text" name="username" id="username" size="40"/>
Password<br />
<input type="password" name="password" id="password" size="40"/>
<br />
<br />
<br />
<input type="submit" name="button" id="button" value="LogIn"/>
</form>
</div>
<?php include_once("../template_header.php");?>
</div>
</body>
</html>
//index.php
<?php
session_start();
if(!isset($_SESSION["member"])){
header("location:admin_login.php");
exit();
}
$managerID = preg_replace('#[^0-9]#i',"",$_SESSION["id"]);
$manager = preg_replace('#[A-Za-z0-9]#i',"",$_SESSION["manager"]);
$password = preg_replace('#[A-Za-z0-9]#i',"",$_SESSION["password"]);
include "../storescripts/connect_to_mysql.php";
$sql = mysql_query("SELECT * FROM admin WHERE id ='managerID' AND username ='$manager' AND password ='$password'LIMIT 1");
$exist_count = mysql_num_rows($sql);
if($exist_count == 0){
echo("Your login session data in not in the database");
exit();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Service Admin Area</title>
<link rel="stylesheet" href="../style/style.css" type="text/css" media="screen"/>
</head>
<body>
<div id="mainWrapper" >
<?php include_once("../template_header.php");?>
<div id="pageContent" >
<div align="left" "style="margin-left:040px;"><h1>Hello Store Manager .What would you loke to do today</h1><br />
<h3><a href="inventory_list.php">Manage Inventory</a></h3><br/><h3><a href="">Manage Me</a></h3><br/></div></div>
<?php include_once("../template_header.php");?>
</div>
</body>
</html>
b $ b
我面临的问题是,我不能登录到我的index.php页面,即使我已经输入正确的用户名和密码在我的数据库中指定,我已经通过phpmyadmin.Everytime设置i尝试登录它调用[echo'这信息不正确,请再次点击这里']如所述在admin_login.php.我有点沮丧。你能帮助我吗?
The problem i am facing is that i am not able to login to my index.php page even after i have put in the correct username and password as specified in my database which i have set through phpmyadmin.Everytime i try to login it invokes the [echo 'This information is incorrect,try again Click Here'] as mentioned in the admin_login.php.I am getting a bit frustrated.Can you help me out guys?
推荐答案
我不知道为什么你使用preg_replace。看来我正在清除变量。这就解释了为什么你不能在数据库中找到自己。尝试删除preg_replace,看看会发生什么。另外当你在SQL查询时忘记了一个空格在你的密码和限制之间。
I am not sure why you use the preg_replace. Looks to me you are clearing the variables. Which explains why you cant find yourself in the database. Try to remove the preg_replace and see what happens. Also when you when you the SQL query you forgot a space between your password and limit.
希望这解决了您的问题
这篇关于即使输入正确的值后也不能登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!