mercredi 30 décembre 2020

form with multiplie data with checkboxes

i have table of procuts (data come from database)

  <?php
    while($row3 = mysqli_fetch_array($result2)) {
     $prodname = $row3['name'];
     $supid = $row3['supplier'];
     $prodid = $row3['id'];
     $prodprice = $row3['price'];
  ?>
            <tr class='listtable'>
              <td><input type="checkbox" name="prod[]" id="prod[<?php echo $prodid; ?>]" value="<?php echo $prodid; ?>"><label for="prod[<?php echo $prodid; ?>]"><?php echo $prodname; ?></label>
              </td>
              <td><label for="prod[<?php echo $prodid; ?>]"><?php echo $prodprice; ?> NIS
              </td></label>
              <td><input type="text" name="qty" placeholder="Qty" minlength="1" maxlength="3" size="2">
              </td>
            </tr>
    <?php
    }
    ?>

i want to send the data of each row if the checkbox is selected... i can send the checkbox value (i sent the producs ID to get the data from the database for each one is selected but i cant send the Qty text box value (i want to send only the ones are checked)

<?php  
include "db.php";
  if(isset($_POST['submit'])){
      if(!empty($_POST['prod'])){
        foreach($_POST['prod'] as $pid){
          $proddetail = mysqli_query($con,"SELECT * FROM `products` WHERE id = $pid");
          while($prod = mysqli_fetch_array($proddetail)) {
            $pname = $prod['name'];
            $pprice = $prod['price'];
            echo $pname;
            echo $pprice;
            echo "<br>";
          }
        }
      } else {
        echo 'no items selected!';
      }
  }
?>  



Aucun commentaire:

Enregistrer un commentaire