hye ..现在使用session..right进行多级登录现在我在此行中收到错误未定义索引userId ..当我尝试输入正确的用户名和密码时,它确实显示警告消息并显示未定义索引错误
if ($data['role' == "partner"]) {
$_SESSION['partner'] = $data['userId'];
?>
<script>alert('You are log as industrial partner ...')
window.location='index.html'</script>
<?php
} else if ($data['role' == "student"]) {
$_SESSION['student'] = $data['userId'];
?>
<script>alert('You are log as student ...')
window.location='index.html'</script>
<?php
我哪里错了..?有人可以帮助我..这是我的完整代码
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
SESSION_start();
include ('Connections/connect.php');
if(isset($_POST['submit']))
{
$username = $mysqli->real_escape_string($_POST['txtUsername']);
$password = $mysqli->real_escape_string($_POST['txtPassword']);
if ($username == "" || $password == "") {
?>
<script> alert('Please enter username and password ...')
window.location='mainpage.html'</script>
<?php
} else {
$query = ("SELECT username,password FROM tbluser WHERE username='$username' AND password='$password'");
$result = $mysqli->query($query);
$data = $result->fetch_array();
$count = $result->num_rows;
if ($count>0) {
if ($data['role' == "partner"]) {
$_SESSION['partner'] = $data['userId'];
?>
<script>alert('You are log as industrial partner ...')
window.location='index.html'</script>
<?php
} else if ($data['role' == "student"]) {
$_SESSION['student'] = $data['userId'];
?>
<script>alert('You are log as student ...')
window.location='index.html'</script>
<?php
} else {
?>
<script>alert('Username or password does not match ...')
window.location='mainpage.html'</script>
<?php
}
}
}
}
?>
答案 0 :(得分:1)
您只从MySQL获取“用户名”和“密码”,因此$data
数组只包含这两个键。