简体   繁体   中英

Update Multiple date column in while loop in PHP

Form with only one date column needs to be updated. But I am unable to feed different date on the form.

html/php form code below:

<td><form id="form2" name="form2" method="post">
  <table  width="100%" >
    <tr><td colspan="10" align="left"><h3>Container Details</h3>
        </td></tr>enter code here
    <tr>
      <td><table  width="100%" >
        <tr>
          <td><strong>CONTAINER NO</strong></td>
          <td><strong>CONTAINER SIZE</strong></td>
          <td><strong>CONTAINER CATEGORY</strong></td>
          <td><strong>IGM NO.</strong></td>
          <td><strong>LINE NO.</strong></td>
          <td><strong>BOE NO.</strong></td>
          <td><strong>GATE IN DATE</strong></td>
          <td><strong>EXPECTED DELIEVRY DATE</strong></td>
          <td><strong>GATE OUT DATE</strong></td>

        </tr>
    <?php 
    $i=0;
        while($r = mysqli_fetch_row($res)){
        ++$i;
        ?>
        <tr>
          <td><input type="hidden" name="vci_no[]" id="vci_no" value="<?php echo @$r['0']; ?>"><?php echo @$r[1]; ?></td>
          <td><?php echo @$r[2]; ?></td>
          <td><?php echo @$r[3]; ?></td>
          <td><?php echo @$r[4]; ?></td>
          <td><?php echo @$r[5]; ?></td>
          <td><?php echo @$r[6]; ?></td>
          <td><?php echo ((date('d-m-Y', strtotime($r['7']))==date('d-m-Y', strtotime('')))?"":date('d-m-Y', strtotime($r[7]))); ?></td>
          <td><input type='text' name='gateout_plnd_dt[]' value='<?php echo((date('d-m-Y', strtotime($r[8]))==date('d-m-Y', strtotime('')))?"":date('d-m-Y', strtotime($r[8]))) ?>'  class='dt' id="gateout_plnd_dt<? echo $r[0]; ?>"/>
         </td><input type="submit" name="save" id="save" value="Update" onClick="return validateUpdateWo()">

Updated code:

if(isset($_REQUEST['save'])){   
     $gateout_plnd_dt = $_REQUEST['gateout_plnd_dt'];
    $vci_no = $_REQUEST['vci_no'];
    echo sizeof($vci_no);echo sizeof($gateout_plnd_dt);

    for($i=0; $i<sizeof($vci_no); $i++){


      mysqli_query($con, "update veh_cont_import set gateout_plnd_dt= '".date('Y-m-d', strtotime(urlencode($gateout_plnd_dt[$i])))."'
                           where vci_no = '".mysqli_real_escape_string($con, $vci_no[$i])."'") or die(mysqli_error($con));
    }

I am unable to select date in any of the column expect the first one.

屏幕截图

I have also tried passing different id for input type through PHP but same result like below:

id="gateout_plnd_dt<? echo $r[0]; ?>"

Totally other answer,

make the names as following:

  • gateout_plnd_dt[1]
  • gateout_plnd_dt[2]
  • gateout_plnd_dt[n]

Then the array will have indices and then you can check the not empty ones with php

$array = filter_input(INPUT_POST,'gateout_plnd_dt');
foreach($array as $key => $item){
      if(strlen($item) > 0){ 
          echo "$key has the value $item" . PHP_EOL;
      }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM