加载页面时会话的未定义索引错误

I am getting error "Undefined index: Msg in Employee.php " when am deleting the employee. Am trying to display the session value from employeedb.php. Here is my employee.php. Here am trying to display session message inside the div "divGuestRegisterContainer"

<?php
require_once("includes.php");
<div id="divGuestRegisterContainer" >
<b>
<?php   
if($_SESSION["Msg"]!="")
{
?>
<ul>
<li>
<b><?php 
echo $_SESSION["Msg"];
?>
</b>
</li>
</ul>
<?php
$_SESSION["Msg"]="";
}
?>
</b>
<ul>
<li>
<span style="width:120px;">Employee Name :</span>
<input type="text" name="txt_empname" id="txt_empname" class="textbox" value="<?php echo $emp_name;?>" />                       
</li>
<li >
<input type='button' id='btnDelete' name='btnDelete' class='button' value='Delete' onclick='deleteEmployee()' style='margin-left:10px;width:85px;display:inline' />
</li>
</ul>
</div>
?>

I am passing the $_SESSION["Msg"] value from employeedb.php to employee.php this is my employeedb.php

<?php
require_once("includes.php");
$genObj=new general();
$type=$_GET["type"];
$emp_id=$_POST["HFEmpID"];
if($type=="delete")
{
mysql_query("UPDATE employee SET del_flag=1 WHERE emp_id=".$emp_id."");
$_SESSION["Msg"]="Employee details deleted successfully!";
}
 header( 'Location:Employee.php');
?>

When am clicking on delete button , am calling this javascript function, this is my javascript function.

function deleteEmployee()
{
var del = confirm("Are you sure you want to delete this Employee?");
if (del == true)
{
document.forms[0].action="employeeDB.php?type=delete";
document.forms[0].submit();
}
else
{
document.forms[0].action="employeeDB.php";
}
}

this is my includes.php where I started session already

<?php
session_start();
ob_start();
//Session Starts    
require_once("config/config.php");      
require_once("config/dbcon/dbcon.php");
require_once("classes/csGeneral.php");
require_once("classes/csPager.php");
require_once("classes/csImageFunctions.php");
require_once("classes/striptag.php");
/* $_SESSION["returnURL"]=$_SERVER['HTTP_REFERER'];  */
$genCheckUser=new general();
$genCheckUser->getUserIDCookie();
?>

In your code you just echoed $_SESSION['Msg']

<b><?php  echo $_SESSION["Msg"]; ?> </b>

this will have error at the start because you havent set a value for this one because you havent done delete before so in order to remove the error

So you must add the condition that if $_SESSION['Msg'] is not yet set dont echo it..

<b><?php  if(!empty($_SESSION['Msg'])){ echo $_SESSION["Msg"];} ?> </b>
session_start();
ob_start();

should be:

ob_start();
session_start();
.
.
.
ob_flush();       <------- last statement

You have to check if the variable indeed exists before checking if its empty.

So change line 6 to:

if (isset($_SESSION['Msg']))

From the PHP manual :

isset — Determine if a variable is set and is not NULL