未定义的索引(未识别隐藏)

时间:2013-02-20 12:44:21

标签: php

运行以下代码时出现以下错误:

Notice: Undefined index: hid in E:\Program Files\xampp\htdocs\cont.php

echo "<table align='right'><tr><td><a href='cont.php?hid=101'><input type='button' value='Account Settings'></a></td></tr></table>";

cont.php代码:

$con = mysql_connect("localhost","Rahul","");
    mysql_select_db("ebusiness", $con);

if($_SESSION['id']==1)
    {
 include 'business.php';
}
else if($_GET['hid']==101)
{
    session_start();
     include 'edprofile.php';
}

5 个答案:

答案 0 :(得分:3)

您正在直接检查$_GET['hid'],而不检查是否已设置。

else if(isset($_GET['hid']) && $_GET['hid'] == 101)

答案 1 :(得分:0)

试试这段代码:

添加:$hid = isset($_GET['hid'])?$_GET['hid']:"";

已修改:$_GET['hid']else if($hid==101)

$con = mysql_connect("localhost","Rahul","");
    mysql_select_db("ebusiness", $con);

$hid  = isset($_GET['hid'])?$_GET['hid']:"";

if($_SESSION['id']==1)
    {
 include 'business.php';
}
else if($hid==101)
{
    session_start();
     include 'edprofile.php';
}

答案 2 :(得分:0)

更改此行:

else if($_GET['hid']==101)

为:

else if(isset($_GET['hid']) && $_GET['hid']==101)

答案 3 :(得分:0)

请记住,当您在页面上使用GET或POST时,无法保证已发送某个变量,因为默认情况下HTTP协议是无状态的。

变量存在是非常重要的,并且变量也是有效的。为此,isset()方法非常有用。我建议你做一个

isset($_GET['hid'])

在if语句的代码中

答案 4 :(得分:0)

您也缺少在获取请求时传递hid变量(在U​​RL中)。看看这个。它shuld内容?hid = 101或&amp; hid = 101 some where。

并使用

替换你的其他条件
else if(isset($_GET['hid']) && $_GET['hid']==101)