【问题标题】:PhP and mySQL testingPhP 和 mySQL 测试
【发布时间】:2014-04-21 03:00:32
【问题描述】:

我一直在尝试测试登录 php,但在输入用户名和密码后,我收到此错误(注意:未定义索引:第 12 行 /web/stud/u1177827/store_admin/admin_login.php 中的用户名注意:未定义索引:第13行/web/stud/u1177827/store_admin/admin_login.php中的密码连接失败。该信息不正确,重试单击此处) 这是代码:

<?php
session_start();
if(isset($_SESSION["staff"])){
    header("location:index.php");
    exit();
}
?>
<?php
// Prase the log in form if the user has filled it out and pressed "Log in"
if(isset($_POST["username"])&& isset($_POST["password"])){

$username=preg_replace('#[^A-Za-z0-0]#i',"",$_SESSION["username"]);//filter everything but numbers and letters
$password=preg_replace('#[^A_Za-z0-9]#i',"",$_SESSION["password"]);//filter everything but numbers and letters
//Connect to the MySQL database
include "../storescripts/connectToMySQL.php";
$sql=mysql_query("SELECT*FROM B4UStaff WHERE fname='$username' AND lname='$password'LIMT 1");//query the person
//..... MAKE SURE PERSON EXISTS IN DATABASE....
$existCount=mysql_num_rows($sql);//count the row nums
if($existCount==1){//evaluate the count
while($row=mysql_fetch_array($sql)){
    $staffNo=$row["staffNo"];
}
$_SESSION["staffNo"]=$staffNo;
$_SESSION["username"]=$username;
$_SESSION["password"]=$password;
header("location:index.php");
exit();
} else{
    echo 'That information is incorrect, try again <a href="index.php">Click Here</a>';
    exit();
}
}
?>

有人知道怎么解决吗?

【问题讨论】:

    标签: php mysql sql session


    【解决方案1】:

    更正这两行而不是 SESSION 你必须像这样使用 POST

    $username=preg_replace('#[^A-Za-z0-0]#i',"",$_POST["username"]);//filter everything but numbers and letters
    $password=preg_replace('#[^A_Za-z0-9]#i',"",$_POST["password"]);//filter everything but numbers and letters
    

    【讨论】:

      【解决方案2】:

      只需用 $_POST 更改 $_SESSION:

      $_SESSION["username"]
      $_SESSION["password"]
      

      $_POST["username"]
      $_POST["password"]
      

      在您的代码中,您需要获取这两个 POST 变量并将其设置为 SESSION 变量并使用 staffNo 是正确的。

      【讨论】:

        猜你喜欢
        • 2011-08-01
        • 1970-01-01
        • 2014-08-03
        • 1970-01-01
        • 1970-01-01
        • 2012-12-01
        • 2019-11-04
        • 2013-05-02
        • 1970-01-01
        相关资源
        最近更新 更多