我正在尝试定义我的变量$ isadmin在我的会话中使用,但我继续得到错误'Undefined variable:isadmin'
这是我的代码:
<?php
session_start();
ini_set("error_reporting",E_ALL & ~E_NOTICE);
ini_set("display_errors",1);
if ($_POST['username'] != '' || $_POST['password'] != '')
{
include_once $_SERVER['DOCUMENT_ROOT'] . "/flourish/toinclude.php";
$mydb=new fDatabase("mssql", "finance","mytest","",61495);
$result = $mydb->query("SELECT * FROM person WHERE personname=%s AND password=%s", $_POST['username'], $_POST['password']);
$isadmin = $mydb->query("SELECT isadmin FROM person");
if($result->countReturnedRows() == 0)
{
$badaccount = "Incorrect User Id or Password entered, please try again.";
}
else
{
$fetchresult = $result->fetchRow();
$userid = $fetchresult['username'];
if($isadmin=='N' || $isadmin=='Y')//As you mention in the question
//That admin column of two value one is N and one is Y
$_SESSION['admin']=$isadmin;
header("location:mainpage.php");
}
}
?>
答案 0 :(得分:0)
添加行
$isadmin = $fetchresult['isadmin'];
below
$userid = $fetchresult['username'];
因为您没有将isadmin表值分配给变量,所以它仍未定义。