I want to update all table rows using one submit form ,and I find this way that i make the name of the input implement an array but I can't get it's values plus I'm getting undefined index for foo array. my code:
<form class="form-horizontal form-row-seperated"
enctype="multipart/form-data" action="updateSetting.php" method="post">
<div class="portlet">
<div class="portlet-body">
<?php while ($row = mysqli_fetch_array($result)){ ?>
<div class="form-group">
<label class="col-md-2 control-label"><?php echo $row['title_en'] ?>
<span class="required"> * </span>
</label>
<div class="col-md-10">
<input type="text" class="form-control" placeholder=""
value="<?php echo $row['value'];?>" name="foo[<?php echo $row['setting_id']; ?>] "
>
<!-- <input type="text" name="foo[--><?php //echo $row['key']; ?><!--]" value='--><?php //echo $row['key'];?><!--' />-->
<span class="help-block"></span>
</div>
</div>
<?php } ?>
</div>
<div class="portlet margin-bottom">
<button class="btn btn-primary pull-right btn-lg" type="submit" value="submit" id="submit">
<i class="fa fa-check"></i> Edit
</button>
<div class="clearfix"></div>
</div>
</form>
updateSetting.php
<?php $value=$_POST['foo[]'];
foreach ($_POST['foo'] as $key => $value) {
$sql1 = "UPDATE settings SET value='$value' WHERE setting_id='$key'"
or
die(mysqli_error());
$result1 = mysqli_query($sql1);
}
echo "update complete";
can any one tell me what's my mistake or give me another suggestion to update the rows in one form ...thanks in advance