dimanche 29 mai 2016

For loop in php and oracle

I have created a checkbox form with attribute medicine name, stock quantity and quantity. User can tick on any medicine name and for quantity user need to fill by themselves. When i tick and insert quantity for the first two row, my data successfully saved into my database. Below is the image for my checkbox form.

My checkbox form

But when i tick on the second and the third row,the medicine name successfully insert into database, but the quantity insert into my database is 'null'.

My checkbox form

checkbox.php

     <input type="checkbox" name="MEDICINE_ID[]" value="<?php echo $row['MEDICINE_ID'] ?>" id="check_item" align="middle" />
     </div></td>      
     <td align="center">
       <?php
          echo $row ["MEDICINE_NAME"];
       ?>      
     </td>

     <td align="center">
      <?php
         echo $row ["STOCK_QUANTITY"] ," ", $row ["MED_FORM"];
      ?>      
     </td>

    <td><label>
    <input name="quantity[]" type="number" max="<?php echo $row['STOCK_QUANTITY'] ?>" min='1' id="quantity" value="" size="1000" />
    </label></td>

   <?php
      $i++;
   ?>

checkboxprocess.php

  <?php
     $conn = oci_connect("username", "pass", "orcl");

     $matric_No = $_POST['matric_No'];
     $medicine_ID = $_POST['MEDICINE_ID'];
     $quantity = $_POST['quantity'];
     $dates =  $_POST['dates'];

     $size_medicine=sizeOf($medicine_ID);

        for($i=0;$i<$size_medicine;$i++){       
             $statement="insert into stud_med(quantity,matric_No,medicine_ID,dates) 
             VALUES('$quantity[$i]','$matric_No','$medicine_ID[$i]',to_date('$dates','yyyy-mm-dd'))";
             $state = oci_parse($conn,$statement ); 
             oci_execute($state);   
}
   ?>




Aucun commentaire:

Enregistrer un commentaire