Updating dynamic data in a table

263
March 20, 2017, at 4:13 PM

I have a table populated with mysql data. I want to update data at once. But the problem is if I don't update the first row it does not continue to the second row. Please see below my codes.

//this is inside while loop that fetch data in mysql database
<td><input type='text' name='item[]' value='<?php echo $item;?>' class='form-control1' readonly = 'readonly'></td>
<td><input type='text' name='qty[]' value='<?php echo $qty;?>' class='form-control1' readonly = 'readonly'></td>
<td><input type='text' name='serial[]' value='<?php echo $serial;?>' class='form-control1' readonly = 'readonly'></td>
<td><input type='date' name='expdate[]' value='<?php echo $row['expdate'];?>' class='form-control1 bday'></td>
<td><input type='text' name='bin[]' value='<?php echo $bin; ?>' class='form-control1' readonly = 'readonly'></td>
<td width="10%" align="center">
    <select class="form-control1" name="bin_id[]" id="bin_id">
    <?php
        require "connect/db.php";
        $sql = "select bin_id FROM location_bin";
        $res   = mysqli_query($mysqli, $sql);
            while($row = mysqli_fetch_array($res)){
                echo "<option value='".$row['bin_id']."'>".ucfirst($row['bin_id'])."</option>";
            }
        }
    ?>
    </select></td>
<td><input type="text" class="form-control1" id="qtytr" name="qtytr[]"></td>

//my form submit action
<?php
if($_POST['save']){
    require "connect/db.php";
    for ($i=0; $i<count($_POST['item']); $i++) 
    { 
    $item = $_POST['item'][$i];
    $bin = $_POST['bin'][$i];
    $qty = $_POST['sqty'][$i];
    $expdate = $_POST['expdate'][$i];
    $serial = $_POST['serial'][$i];
    $bin_id = $_POST['bin_id'][$i];
    $qtytr = $_POST['qtytr'][$i];
    mysqli_query($mysqli, "UPDATE put_in SET expdate = '$expdate' where ID = '$id'");
    if($qtytr && $bin_id){  
        if($qtytr <= $qty){
            //update query here.
            echo 'success!'; 
        }
        }else{
                echo "Qty is not sufficient";
                }
    }else{
                echo "Select bin ID and Input Quantity";
                }
   }
}
?>  

I simplify the code because its too long. This is for transferring item to another bin. So the last two column needs user input from where the item should be transfer and the qty for transfer. So the problem is if I just want to update the second row. it outputs "Select bin ID and Input Quantity". Unless I select bin and quantity on the first row then it is successfully updated.

Rent Charter Buses Company
READ ALSO
Using PHP 7.1 with OPcache enabled, do YML and INI files are stored in memory?

Using PHP 7.1 with OPcache enabled, do YML and INI files are stored in memory?

Some CMS/Frameworks stores configuration data on YML or INI filesIf my application have thounsands of those files, and just a small number of PHP files that are using the configuration ones, just the PHP files are stored in memory?, or all included files in this case YML and INI, are too stored?

305
How to redisplay blank html form in php after validation on submit fails. Without using header redirect?

How to redisplay blank html form in php after validation on submit fails. Without using header redirect?

I am new to php, this is my first post, my apologies about the formatting and the sloppiness of my codingI'm not sure exactly how to post code

334