Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PhP和mySQL测试_Php_Mysql_Sql_Session - Fatal编程技术网

PhP和mySQL测试

PhP和mySQL测试,php,mysql,sql,session,Php,Mysql,Sql,Session,我一直在尝试测试登录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"])){ he

我一直在尝试测试登录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();
}
}
?>


更正这两行而不是会话你必须像这样使用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

只需使用$\u POST更改$\u会话即可:

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

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

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