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 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)