Link to home
Start Free TrialLog in
Avatar of ats2012
ats2012

asked on

Issue with submitting an array php form

I have a form that displays some information from a database that puts everything in a table and you are able to edit all the tables. Is issue i am having is when i click submit it says it can't find the index data_id, says its undefined. Code is below.

Table:
<form id="form" class="form-horizontal" role="form" data-toggle="validator" method="post" name="edit_interface.php">
			
			<div class="form-group">
					<label class="control-label col-sm-3" for="type">Type:</label>
					<div class="col-sm-6">
					<input name="type" class="form-control" id="type" value="<?php echo $data_interface['interface_type']; ?>">
					</div>
			</div>
			<div class="form-group">
					<label class="control-label col-sm-3" for="ip_address">IP Address:</label>
					<div class="col-sm-6">
					<input name="ip_address" class="form-control" id="ip_address" value="<?php echo $data_interface['ip_address']; ?>">
					</div>
			</div>
</div>
</div>
</div>
			<div class="col-sm-12">	
<div class="panel panel-primary">
                        <div class="panel-heading">
                             ATS Sites
                        </div>
                        <div class="panel-body">
                            <div class="table-responsive">
                                <table class="table table-striped table-bordered table-hover" id="edit_interface">
								<?php
$query_interface_data = mysql_query("SELECT * FROM site_router_interface_info WHERE router_interface_id = '$interface_id'") or die (mysql_error());

echo "<thead>";
echo "<tr>";
echo "<th>";
echo "<b>Delete Interface:</b>";
echo "</th>";
echo "<th>";
echo "<b>ID:</b>";
echo "</th>";
echo "</th>";
echo "<th>";
echo "<b>Name:</b>";
echo "</th>";
echo "<th>";
echo "<b>Speed:</b>";
echo "</th>";
echo "<th>";
echo "<b>Vendor:</b>";
echo "</th>";
echo "<th>";
echo "<b>LEC ID:</b>";
echo "</th>";
echo "<th>";
echo "<b>DID:</b>";
echo "</th>";
echo "<th>";
echo "<b>Account ID:</b>";
echo "</th>";
echo "<th>";
echo "<b>Circuit ID:</b>";
echo "</th>";
echo "<th>";
echo "<b>Support Number:</b>";
echo "</th>";
echo "<th>";
echo "<b>Notes:</b>";
echo "</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";

while ($info = mysql_fetch_assoc($query_interface_data))
{

$data_id = $info['id'];
$name = $info['name'];
$speed = $info['speed'];
$vendor = $info['vendor'];
$lec = $info['lec'];
$did = $info['did'];
$account_id = $info['account_id'];
$support_number = $info['support_number'];
$circuit_id = $info['circuit_id'];
$notes = $info['notes'];

echo "<tr>";
?>
<td align='middle'>
<a href=remove_router_interface_data.php?id=<?php echo $id; ?>&interface_id=<?php echo $interface_id ?>&router_id=<?php echo $router_id ?>&data_id=<?php echo $data_id; ?> onclick="return confirm('Are you sure you want to Delete this Item?')"><img src='assets/img/decommission_asset.png' width='30' height='30' align='middle'/></a>
</td>
<td><input size="10" class="form-control" type="text" name="data_id[]" value="<?php echo $data_id ?>" readonly> 
</td>
<td><input size="10" class="form-control" type="text" name="name[]" value="<?php echo $name ?>"> 
</td>
<td><input size="15" class="form-control" type="text" name="speed[]" value="<?php echo $speed ?>"> 
</td>
<td><input size="10" class="form-control" type="text" name="vendor[]" value="<?php echo $vendor ?>"> 
</td>
<td><input size="10" class="form-control" type="text" name="lec[]" value="<?php echo $lec ?>"> 
</td>
<td><input size="10" class="form-control" type="text" name="did[]" value="<?php echo $did ?>"> 
</td>
<td><input size="10" class="form-control" type="text" name="account_id[]" value="<?php echo $account_id ?>"> 
</td>
<td><input size="10" class="form-control" type="text" name="circuit_id[]" value="<?php echo $circuit_id ?>"> 
</td>
<td><input size="10" class="form-control" type="text" name="support_number[]" value="<?php echo $support_number ?>"> 
</td>
<td><input size="10" class="form-control" type="text" name="notes[]" value="<?php echo $notes ?>"> 
</td>
<?php
echo "</tr>";

}
?>

</tbody>
			</table>
                        </div>
                        </div>
						
                    </div>
					<button name='form' type="submit" class="btn btn-primary" id="submit"> Edit Interface</button>	
            </form>

Open in new window


Here is the code when you click the button:

if($_SERVER['REQUEST_METHOD'] == "POST") {

$type = $_POST['type'];
$ip_address = $_POST['ip_address'];

mysql_query("UPDATE site_router_interface SET 
interface_type='".$type."',
ip_address='".$ip_address."'
WHERE id = '".$interface_id."'") or die (mysql_error()); 

for ($i=0; $i < count($_POST['data_id']); $i++){

$data_id = $_POST['data_id'][$i];
$name = $_POST['name'][$i];
$speed = $_POST['speed'][$i];
$vendor = $_POST['vendor'][$i];
$lec = $_POST['lec'][$i];
$did = $_POST['did'][$i];
$account_id = $_POST['account_id'][$i];
$support_number = $_POST['support_number'][$i];
$notes = $_POST['notes'][$i];


mysql_query("UPDATE site_router_interface_info SET 
name='".$name."',
speed='".$speed."',
vendor='".$vendor."',
lec='".$lec."',
did='".$did."',
account_id='".$account_id."',
support_number='".$support_number."',
notes='".$notes."'
WHERE id = '".$data_id."'") or die (mysql_error());

}
echo "Interface Saved";


/*
	$server = $_SERVER['HTTP_HOST'];
$current_folder = basename(dirname(__FILE__));

header( "Location: http://$server/$current_folder/router_information.php?id=$id&router_id=$router_id" ) ;
*/
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Mark Brady
Mark Brady
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ats2012
ats2012

ASKER

Thanks. I got it working
B Grade? I showed you where you issue was. How is that a B grade?