Trojan Trojan - 5 months ago 22
HTML Question

undefined index error when update button is pressed?

i have here a select option and it work fine if i change the value of the option but when i try not to change anything and i pressed on the update button it gives me an error of

undefined error
. but if i change the value of a option it successfully updated. I really do not know why its giving me this error..

my code

<?php
include_once 'db.php';


$Reason_for_Deduction = isset($_GET['Summary_of_Reason']) ? $_GET['Reason_for_Deduction'] : '';

if(isset($_POST['update']))
{
$ID = $_GET['ID'];
$Reason_for_Deduction = $_POST['Summary_of_Reason'];

if($LTID->update($ID,$Summary_of_Reason))
{
echo "<script type='text/javascript'>alert('Successfully Updated!');</script>";
}
else
{
echo "<script type='text/javascript'>alert('Updating Failed!');</script>";
}
}
if(isset($_GET['ID']))
{
$ID = $_GET['ID'];
extract($LTID->getID($ID));
}
?>


update.php

<select name="Summary_of_Reason" id="yearapproved" class=form-control required/>
<option selected="true" disabled="disabled" <?php echo $Summary_of_Reason; ?>><?php echo $Summary_of_Reason; ?></option>
<option value="18% SLOPE ABOVE AND UNDEVELOPED">18% Slope and Undeveloped</option>
<option value="FIVE (5) HAS. AND BELOW">5 Has. and Below</option>
<option value="CANCELLED TITLE">Cancelled Title</option>
<option value="CANNOT BE LOCATED ON THE GROUND">Cannot Be Located on the Ground</option>
<option value="COMMUNAL FOREST">Communal Forest</option>
<option value="DISTRIBUTED BEFORE CARPER">Distributed Before Carper</option>
<option value="DUPLICATE LH">Duplicate Lh</option>
<option value="ERODED; SILTED/ROCKY NOT SUITABLE TO AGRICULTURAL">Eroded;Silted/Rockt not suitable to Agricultural</option>
<option value="HANDOG TITULO">Handog Titulo</option>
<option value="HOMESTEAD PATENT">Homestead Patent</option>
<option value="IRRIGATION CANAL">Irrigation Canal</option>
<option value="LANDS FOR PUBLIC USE">Lands for Public Use</option>
<option value="LH IS W/N SWAMPY, MANGROVE AREA">Lh is w/n Swampy, Mangrove Area</option>
<option value="LO DIED PRIOR TO CARP">LO Died Prior to CARP</option>
<option value="PASTURE LAND">Pasture Land</option>
<option value="ROAD LOT">Road Lot</option>
<option value="TIMBERLAND">Timberland</option>
<option value="USED FOR INFRASTRUCTURE">Used for Infrastructure</option>
<option value="W/N PROCLAIMED AREA">w/n Proclaimed Area</option>
<option value="W/N DANGER ZONE">w/n Danger Zone</option>
<option value="W/N UNCLASSIFIED PUBLIC FOREST">w/n Unclassified Public Forest</option>
<option value="W/N WATERSHED AREA">w/n Watershed Area</option>
<option value="WORKABLE">Workable</option>
</select>

Answer

You should change this line:

<option selected="true" disabled="disabled" <?php echo $Summary_of_Reason; ?>><?php echo $Summary_of_Reason; ?></option>

to:

<option selected="selected" disabled="disabled" value="<?php echo $Summary_of_Reason; ?>"><?php echo $Summary_of_Reason; ?></option>

You are echoing the value of $Summary_of_Reason inside the option tag and not as its value.