Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.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登录错误_Php - Fatal编程技术网

php登录错误

php登录错误,php,Php,我在线下载了一个基本系统的脚本,该系统将使用用户名admin和密码admin进行用户登录, 但是脚本在登录页面上有一个小错误,似乎有一个变量没有声明,我可以看到这个变量没有从表单中声明,但是我不能以一种可以使它工作的方式声明。我需要一种从表单输入中声明$position变量的方法,以便它与login.php配合使用 这里是错误 注意:未定义的索引:在C:\程序中的位置 第20行的Files\EasyPHP-5.3.3\www\preenrolmentsystem\login.php 源代码有两个

我在线下载了一个基本系统的脚本,该系统将使用用户名admin和密码admin进行用户登录, 但是脚本在登录页面上有一个小错误,似乎有一个变量没有声明,我可以看到这个变量没有从表单中声明,但是我不能以一种可以使它工作的方式声明。我需要一种从表单输入中声明
$position
变量的方法,以便它与login.php配合使用 这里是错误

注意:未定义的索引:在C:\程序中的位置 第20行的Files\EasyPHP-5.3.3\www\preenrolmentsystem\login.php

源代码有两个页面,一个是login.php,另一个是formform.php

下面是login.php的源代码

<?php
//Start session
session_start();

//Connect to mysql server
include('connect.php');

//Function to sanitize values received from the form. Prevents SQL injection
function clean($str) {
    $str = @trim($str);
    if(get_magic_quotes_gpc()) {
        $str = stripslashes($str);
    }
    return mysql_real_escape_string($str);
}

//Sanitize the POST values
$login = clean($_POST['id']);
$password = clean($_POST['password']);
$position = clean($_POST['position']);
$result = mysql_query("SELECT * FROM user WHERE idnumber='$login' AND password='$password'");
while($row = mysql_fetch_array($result))
    {
    $position = $row['position'];
    }
if ($position=='admin')
{
    //Create query
    $qry="SELECT * FROM admin WHERE idnum='$login' AND password='$password'";
    $result=mysql_query($qry);
    //while($row = mysql_fetch_array($result))
//  {
//  $level=$row['position'];
//  }
    //Check whether the query was successful or not
    if($result) {
        if(mysql_num_rows($result) > 0) {
            //Login Successful
            session_regenerate_id();
            $member = mysql_fetch_assoc($result);
            $_SESSION['SESS_MEMBER_ID'] = $member['id'];
            session_write_close();
            //if ($level="admin"){
            header("location: admin/index.php");
            exit();
        }else {
            //Login failed
            header("location: loginform.php");
            exit();
        }
    }else {
        die("Query failed");
    }
}
if ($position=='student')
{
    //Create query
    $qry="SELECT * FROM prereg WHERE idnumber='$login' AND password='$password'";
    $result=mysql_query($qry);
    //while($row = mysql_fetch_array($result))
//  {
//  $level=$row['position'];
//  }
    //Check whether the query was successful or not
    if($result) {
        if(mysql_num_rows($result) > 0) {
            //Login Successful
            session_regenerate_id();
            $member = mysql_fetch_assoc($result);
            $_SESSION['SESS_MEMBER_ID'] = $member['id'];
            $_SESSION['SESS_FIRST_NAME'] = $member['idnumber'];
            session_write_close();
            //if ($level="admin"){
            header("location: student/profile.php");
            exit();
        }else {
            //Login failed
            header("location: loginform.php");
            exit();
        }
    }else {
        die("Query failed");
    }
}
if ($position=='Casher')
{
    //Create query
    $qry="SELECT * FROM casher WHERE idnumber='$login' AND password='$password'";
    $result=mysql_query($qry);
    //while($row = mysql_fetch_array($result))
//  {
//  $level=$row['position'];
//  }
    //Check whether the query was successful or not
    if($result) {
        if(mysql_num_rows($result) > 0) {
            //Login Successful
            session_regenerate_id();
            $member = mysql_fetch_assoc($result);
            $_SESSION['SESS_MEMBER_ID'] = $member['id'];
            $_SESSION['SESS_FIRST_NAME'] = $member['idnumber'];
            session_write_close();
            //if ($level="admin"){
            header("location: casher/index.php");
            exit();
        }else {
            //Login failed
            header("location: loginform.php");
            exit();
        }
    }else {
        die("Query failed");
    }
}
if ($position=='teacher')
{
    //Create query
    $qry="SELECT * FROM teacher WHERE idnumber='$login' AND password='$password'";
    $result=mysql_query($qry);
    //while($row = mysql_fetch_array($result))
//  {
//  $level=$row['position'];
//  }
    //Check whether the query was successful or not
    if($result) {
        if(mysql_num_rows($result) > 0) {
            //Login Successful
            session_regenerate_id();
            $member = mysql_fetch_assoc($result);
            $_SESSION['SESS_MEMBER_ID'] = $member['id'];
            $_SESSION['SESS_FIRST_NAME'] = $member['idnumber'];
            session_write_close();
            //if ($level="admin"){
            header("location: teacher/index.php");
            exit();
        }else {
            //Login failed
            header("location: loginform.php");
            exit();
        }
    }else {
        die("Query failed");
    }
}

尝试使用类似于:

if (isset($_POST['position'])) {
    //do something with position
    $position = clean($_POST['position']));
} else {
    //position was not set, maybe give it a default value and use that
    $position = null;
}

SanDange当你说“用位置做点什么”时,你的意思是什么?@Lorax cn u给出一个样本有什么理由在表格上没有输入“位置”吗?(查看代码,它可能应该是一个下拉列表,有多种值可供选择,如“admin”、“student”、“teacher”等。)@Lorax:这些值似乎来自用户表。(过账值立即被覆盖。)
if (isset($_POST['position'])) {
    //do something with position
    $position = clean($_POST['position']));
} else {
    //position was not set, maybe give it a default value and use that
    $position = null;
}