douyin8623 2013-03-25 06:14
浏览 52
已采纳

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

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();
?>
  • 写回答

3条回答 默认 最新

  • duanbo5230 2013-03-25 06:19
    关注

    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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序