vendredi 22 septembre 2017

Looped Checkbox Array Value Repeated

I have 4 checkboxes with different values in a while loop & named as an array. The selected value from only the last looped set of checkboxes is being updated yet I need all the selected values to be updated independently to their corresponding rows.

HTML

<input type="checkbox" name="size[]" value="S" />
<input type="checkbox" name="size[]" value="M" />
<input type="checkbox" name="size[]" value="L" />
<input type="checkbox" name="size[]" value="XL" />

PHP

<?php
if(isset($_POST['update'])){
$select_id = "select * from customer where ip='$ip'";
$get_id = mysqli_query($db, $select_id);

while ($row = mysqli_fetch_array($get_id)){
foreach($_POST['size'] as $size){

$product_id = $row['product_id'];

$update_size = "update customer set size='$size' where product_id='$product_id'";
$run_size = mysqli_query($db, $update_size);
}
}
}
?>




Aucun commentaire:

Enregistrer un commentaire