2013-02-20 89 views
0

在運行下面的代碼,我發現了以下錯誤:未定義指數(HID不被識別)

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'; 
} 

回答

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'; 
} 
3

您在$_GET['hid']直接檢查沒有如果設置或不檢查。

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

改變這一行:

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

到:

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

請記住,當你正在使用您的網頁上GET或POST,也不能保證某一個變量已經被髮送,因爲默認情況下HTTP協議是無狀態的。

對於checn而言,存在一個變量是存在的,並且變量是有效的。爲此,isset()方法非常有用。我建議你在你的代碼中的if語句做

isset($_GET['hid'])

0

你也錯過了通過hid變量在你得到請求(在URL中)。一探究竟。它shuld內容?hid = 101或& hid = 101某些地方。

並更換否則,如果條件與

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