Page 1 of 1

Notice: Undefined index:

Posted: Thu Mar 02, 2006 6:31 am
by bazjones
Hey Guys

Can anyone see where im going wrong here??

This is the error im getting

Notice: Undefined index: Update in c:\website\quality_management\incident_log\edit.php on line 142

Code: Select all

<?
$logid = $_GET['logid'];
$db_table = "incidentlog"; 
$query = "SELECT `logid`, `source`, `type`, `logtime`, `logtext` from `$db_table` WHERE `logid` ='$logid'" or die ("Could Not Run Query");
$result = mysql_query($query);
$get_info = mysql_fetch_array($result)
?>
     
<form action="<? echo($_SERVER['PHP_SELF']); ?>" method=POST>
  <table width="129%" border="0">
    <tr> 
      <td width="68"><strong>LogID:</strong></td>
      <td colspan="9"><input type="TEXT" name="logid" size=150 value="<? echo($get_info["logid"]); ?>"> 
      </td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
      <td colspan="9">&nbsp;</td>
    </tr>
    <tr width="100%"> 
      <? 
$source = array("APP1", 
				"APP2",
				"APP3",
           	    "APP4"); 
						
# probably "nicer" to get above list of names from a database table?
echo <<<EOD
  <td><strong>Source:</strong></td> 
  <td><select name="source" id="source"> 
EOD;
# add each eng as an option: 
foreach($source as $value) 
{ 
  $selected = ""; 
  if($value == $get_info["source"]) 
  { 
    # mark this one as the selected entry: 
    $selected = " selected"; 
  } 
  echo "<option$selected>$value</option>\n";
} 
echo <<<EOD
</select></td> 
EOD;
?>
      <? 
$type = array("Event", 
			"Warning", 							
             "Error");   
						
# probably "nicer" to get above list of names from a database table?
echo <<<EOD

  <td><strong>Type:</strong></td> 
  <td><select name="type" id="type"> 
EOD;
# add each eng as an option: 
foreach($type as $value) 
{ 
  $selected = ""; 
  if($value == $get_info["type"]) 
  { 
    # mark this one as the selected entry: 
    $selected = " selected"; 
  } 
  echo "<option$selected>$value</option>\n";
} 
echo <<<EOD
</select></td> 
EOD;
?>

      <td><strong>Time:</strong></td>
      <td width="130">	
	<input name="logtime" type="TEXT" id="cal-field-1" value="<? echo($get_info["logtime"]); ?>" size="10" /> 
          <button type="submit" id="cal-button-1">...</button>
          <script type="text/javascript">
            Calendar.setup({
              inputField    : "cal-field-1",
              button        : "cal-button-1",
              align         : "Tr"
            });
          </script>
	</td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
      <td colspan="9">&nbsp;</td>
    </tr>
    <tr> 
      <td><strong>Description:</strong></td>
      <td colspan="9"><textarea class="textarea" name="logtext" rows=8 cols=150><? echo($get_info["logtext"]); ?></textarea></td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
      <td colspan="9">&nbsp;</td>
    </tr>
	<tr> 
      <td>&nbsp;</td>
      <td colspan="6"><input name="Update" type=SUBMIT class="button" id="Update2" value="Update">
        <input name="Cancel" type="button" id="Cancel" onClick="MM_goToURL('parent','/quality_management/incident_log/incident_report.php');return document.MM_returnValue" value="Cancel"></td>
      <td width="315" colspan="2"><div align="right"> </div></td>
    </tr>
  </table>
  <br>
</form>


<?
if($_POST['Update'])
{
$query = "UPDATE `incidentlog` SET `source` = '". $_POST["source"] ."', `type` = '". $_POST["type"] ."', `logtime` = '".$_POST["logtime"]."', `logtext` = '".$_POST["logtext"]."' WHERE `logid` = '$logid'";
$result = mysql_query($query);
if(!@header("Location: incident_report.php")){ 
echo("<META HTTP-EQUIV=Refresh CONTENT=\"1; URL=incident_report.php\">"); 
echo("<script> 
window.top.location.href = 'incident_report.php'; 
</script>"); 
echo("You should now be redirected to the home page, click <a 
    href='incident_report.php'>here</a> if you are not redirected."); 
};

}
?>

Posted: Thu Mar 02, 2006 6:51 am
by shiznatix
please use php tags when posting php in these forums.

a indefined index is calling a part of a array that does not exist. example:

Code: Select all

$array = array('funk' => 'sucks', 'punk' => 'rocks');

echo $array['funk'];//no problems with that!
echo $array['punk'];//we are still good here!

echo $array['jazz'];//BAM! undefined index
understand?

Posted: Thu Mar 02, 2006 6:58 am
by bazjones
Sorry about the coding tags used, ive changed them now

Yeah i understand what your saying but i still cant find where im going wrong

Maybe im just missing something

Thanks

Posted: Thu Mar 02, 2006 7:05 am
by shiznatix
alright then post the whole page or tell me what line is line 142 because my editor (eclipse) says you only have 120 some lines.

Posted: Thu Mar 02, 2006 7:12 am
by bazjones
Thanks i appreciate you takin time to help me

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<HEAD>
<TITLE>Edit Log Entry</TITLE>
<?php require_once("../../menu/ssw_header.shtml"); ?>
    <script type="text/javascript" src="/jscalendar/calendar.js"></script>
    <script type="text/javascript" src="/jscalendar/calendar-setup.js"></script>
    <script type="text/javascript" src="/jscalendar/lang/calendar-en.js"></script>
    <style type="text/css"> @import url(/jscalendar/calendar-win2k-cold-1.css); </style>
<script language="JavaScript" type="text/JavaScript">
<!--



function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}
//-->
</script>
</head>

<body>
<?php require_once('../../menu/ssw_menu.shtml'); ?>
 
<? include "mysql_connect_incident.php"; ?>

<?
$logid = $_GET['logid'];
$db_table = "incidentlog"; 
$query = "SELECT `logid`, `source`, `type`, `logtime`, `logtext` from `$db_table` WHERE `logid` ='$logid'" or die ("Could Not Run Query");
$result = mysql_query($query);
$get_info = mysql_fetch_array($result)
?>
     
<form action="<? echo($_SERVER['PHP_SELF']); ?>" method=POST>
  <table width="129%" border="0">
    <tr> 
      <td width="68"><strong>LogID:</strong></td>
      <td colspan="9"><input type="TEXT" name="logid" size=50 value="<? echo($get_info["logid"]); ?>"> 
      </td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
      <td colspan="9">&nbsp;</td>
    </tr>
    <tr width="100%"> 
      <? 
$source = array("APP1", 
				"APP2",
				"APP3",
           	    "APP4"); 
						
# probably "nicer" to get above list of names from a database table?
echo <<<EOD
  <td><strong>Source:</strong></td> 
  <td><select name="source" id="source"> 
EOD;
# add each eng as an option: 
foreach($source as $value) 
{ 
  $selected = ""; 
  if($value == $get_info["source"]) 
  { 
    # mark this one as the selected entry: 
    $selected = " selected"; 
  } 
  echo "<option$selected>$value</option>\n";
} 
echo <<<EOD
</select></td> 
EOD;
?>
      <? 
$type = array("Event", 
			"Warning", 							
             "Error");   
						
# probably "nicer" to get above list of names from a database table?
echo <<<EOD

  <td><strong>Type:</strong></td> 
  <td><select name="type" id="type"> 
EOD;
# add each eng as an option: 
foreach($type as $value) 
{ 
  $selected = ""; 
  if($value == $get_info["type"]) 
  { 
    # mark this one as the selected entry: 
    $selected = " selected"; 
  } 
  echo "<option$selected>$value</option>\n";
} 
echo <<<EOD
</select></td> 
EOD;
?>

      <td><strong>Time:</strong></td>
      <td width="130">	
	<input name="logtime" type="TEXT" id="cal-field-1" value="<? echo($get_info["logtime"]); ?>" size="10" /> 
          <button type="submit" id="cal-button-1">...</button>
          <script type="text/javascript">
            Calendar.setup({
              inputField    : "cal-field-1",
              button        : "cal-button-1",
              align         : "Tr"
            });
          </script>
	</td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
      <td colspan="9">&nbsp;</td>
    </tr>
    <tr> 
      <td><strong>Description:</strong></td>
      <td colspan="9"><textarea class="textarea" name="logtext" rows=8 cols=120><? echo($get_info["logtext"]); ?></textarea></td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
      <td colspan="9">&nbsp;</td>
    </tr>
	<tr> 
      <td>&nbsp;</td>
      <td colspan="6"><input name="Update" type=SUBMIT class="button" id="Update2" value="Update">
        <input name="Cancel" type="button" id="Cancel" onClick="MM_goToURL('parent','/quality_management/incident_log/incident_report.php');return document.MM_returnValue" value="Cancel"></td>
      <td width="315" colspan="2"><div align="right"> </div></td>
    </tr>
  </table>
  <br>
</form>


<?
if($_POST['Update'])
{
$query = "UPDATE `incidentlog` SET `source` = '". $_POST["source"] ."', `type` = '". $_POST["type"] ."', `logtime` = '".$_POST["logtime"]."', `logtext` = '".$_POST["logtext"]."' WHERE `logid` = '$logid'";
$result = mysql_query($query);
if(!@header("Location: incident_report.php")){ 
echo("<META HTTP-EQUIV=Refresh CONTENT=\"1; URL=incident_report.php\">"); 
echo("<script> 
window.top.location.href = 'incident_report.php'; 
</script>"); 
echo("You should now be redirected to the home page, click <a 
    href='incident_report.php'>here</a> if you are not redirected."); 
};

}
?>
</body>
<div><hr></div>
<div class="footer">Last Updated: <!-- #BeginDate format:acAm1a -->Thu, March 2, 2006 1:11 PM<!-- #EndDate --></div>
</html>

Posted: Thu Mar 02, 2006 7:15 am
by shiznatix
don't fret it, is there anything else to do at work than help other people learn what you should be doing at the moment :D .

answer:

change line 142 (if ($_POST['Update']))

to

if (!empty($_POST['Update']))

Posted: Thu Mar 02, 2006 7:21 am
by bazjones
Sorry to be a bug but do i also have an error on line 33??

Last question i promise

Thanks

Posted: Thu Mar 02, 2006 7:25 am
by shiznatix
change

$logid = $_GET['logid'];

to

edit: the original would not work if the logid was 0. this will allow 0 through -
$logid = (false !== ($_GET['logid']) ? $_GET['logid'] : '');

don't worry about asking questions, we are all here to help eachother. if i didn't want you to ask questions i wouldn't answer the ones you originally asked :)

Posted: Thu Mar 02, 2006 7:43 am
by bazjones
shiznatix wrote:change

$logid = $_GET['logid'];

to

edit: the original would not work if the logid was 0. this will allow 0 through -
$logid = (false !== ($_GET['logid']) ? $_GET['logid'] : '');
When i do this i now get the same error twice

Notice: Undefined index: logid in c:\website\quality_management\incident_log\edit.php on line 33

Notice: Undefined index: logid in c:\website\quality_management\incident_log\edit.php on line 33

Posted: Thu Mar 02, 2006 7:45 am
by shiznatix
ahhaaaaa sorry i forgot a very important part of that

Code: Select all

$logid = (false !== isset($_GET['logid']) ? $_GET['logid'] : '');
that will work