php - insert html table multiple row to database -


i have tried insert html table multiple row data database not success without error.

please refer below code , kindly advice missed.

retrieve data dropdown selection

<?php     //including database connection file     include_once("config_db.php");     $gettminfo=mysql_query("select * tb_tm order tm_abb");  ?> 

html code table

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head>     <meta http-equiv="content-type" content="text/html; charset=utf-8" />     <link rel="stylesheet" type="text/css" href="css/spa_invoice.css"/>     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> </head>  <body>     <!--add & delete rows table dynamically-->     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>     <script>         $(function(){             $('#addrow').click(function(){                 var html = $('#row_template').html();                 $('#datatable').append(html);                 $(".tablerow").each(function(index) {                     $(this).html(index + 1);                 });             });             $('#deleterow').click(function(){                 $('#datatable .mychkbox:checked').parents('tr').remove();                 calc_ttl();             });             $('#datatable').on('change','.select-desc',function(){                 var cur_val = $(this).val();                 $(this).parents('tr').find('input[name="order_unit_prc[]"]').val(cur_val);             });             $('#datatable').on('keyup','input[name="order_qty[]"]', function(){                 var qty = +$(this).val();                 var unit = +$(this).parents('tr').find('input[name="order_unit_prc[]"]').val();                 $(this).parents('tr').find('input[name="order_amt[]"]').val(qty*unit);                  calc_ttl();             });         });     </script>      <form action="" method="post" name="form_spa_inv">          <fieldset class="row3">             <table>                 <tr>                     <td><input type="button" value="add treatment" id="addrow" /></td>                     <td><input type="button" value="remove treatment" id="deleterow" /></td>                 </tr>             </table>             <table id="datatable" class="form" border="1">                 <tr>                     <td></td>                     <td>no</td>                     <td>description</td>                     <td>qty</td>                     <td>unit price</td>                     <td>amount</td>                 </tr>             </table>              <!-- table row template here -->             <table id="row_template" style="display:none">                 <tr>                     <td><input type="checkbox" name="chk[]" class="mychkbox" /></td>                     <td class="tablerow"></td>                     <td>                         <select name="order_desc[]" id="order_desc" class="select-desc">                             <option value="">-- select treatment --</option>                             <?php                                     while($dd=mysql_fetch_array($gettminfo)) {                         ?>                                     <option value="<?php echo $dd['tm_unit_prc']?>"><?php echo $dd['tm_abb'] ?> - <?php echo $dd['tm_desc'] ?></option>                         <?php                                 }                             ?>                             </select>                     </td>                     <td>                         <input type="text" name="order_qty[]" id="order_qty" size="10">                     </td>                     <td>                         <input type="text" name="order_unit_prc[]" id="order_unit_prc" readonly>                     </td>                     <td>                         <input type="text" name="order_amt[]" id="order_amt" readonly>                     </td>                 </tr>             </table>         </fieldset>          <p style="text-align: center;"><input type="submit" name="submit" value="create">     </form> </body> </html> 

insert mysql query

<?php     //including database connection file     include_once("config_db.php");      if(isset($_post['submit']))     {                for($i=0; $i < count($_post['order_desc']); $i++) {             $order_desc = addslashes($_post['order_desc'][$i]);             $order_qty = addslashes($_post['order_qty'][$i]);             $order_unit_prc = addslashes($_post['order_unit_prc'][$i]);             $order_amt = addslashes($_post['order_amt'][$i]);              //insert data database tb_odr_dtl             $insert_odrdtl=mysql_query("insert tb_odr_dtl(order_desc,order_qty,order_unit_prc,order_amt) values('$order_desc','$order_qty','$order_unit_prc','$order_amt')");             mysql_query($insert_odrdtl);              //display success message             if($insert_odrdtl) {                 echo "<script>alert('invoice created successfully!')</script>";                 echo "<script>window.open('cv.php','_self')</script>";             }         }            } ?> 

change server site code following:

<?php //including database connection file include_once("config_db.php");  if(isset($_post['submit'])) {            for($i=0; $i < count($_post['order_desc']); $i++) {         $order_desc = addslashes($_post['order_desc'][$i]);         $order_qty = addslashes($_post['order_qty'][$i]);         $order_unit_prc = addslashes($_post['order_unit_prc'][$i]);         $order_amt = addslashes($_post['order_amt'][$i]);          //insert data database tb_odr_dtl         $insert_odrdtl=mysql_query("insert tb_odr_dtl(order_desc,order_qty,order_unit_prc,order_amt) values('$order_desc','$order_qty','$order_unit_prc','$order_amt')"); 

//mysql_query($insert_odrdtl); //delete line of code

        //display success message         if($insert_odrdtl) {             echo "<script>alert('invoice created successfully!')</script>";             echo "<script>window.open('cv.php','_self')</script>";         }     }        } 

?>


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -