php $_从数据表POST

uxhixvfz  于 2023-03-07  发布在  PHP
关注(0)|答案(1)|浏览(135)

我有一个表单中的数据表...我的表我有列来设置价格...如果我在同一页上提交表单,$_ POST数据是空的...我需要在提交到mysql数据库后插入它。
数据表:

<tr>
      
      <td>' . $result['Plu'] . '<input type="hidden" name="ideckoSk[]" value="' . $result['Id_sklad_karta'] . '"></td>
      <td>' . $result['Ean'] . '</td>
     
      <td>' . $result['Nazev'] . '</a> </td>
      <td>' . $result['NazevSkupina'] . '</td>
      <td>' . $result['NazevOddeleni'] . '</td>
      <td>' . $result['NazevSklad'] . '<input type="hidden" name="ideckoSkladu[]" value="'.$result['Sklad_Id_sklad'].'"></td>
      
      <td>' . $osetreniTecky['Vnc'] . ' Kč</td>
      <td>' . $osetreniTecky['Nakupni_cena'] . ' Kč</td> 
     <td>' . $osetreniTecky['Cena_dph'] . ' Kč</td>
    
     <td><input class="col-md-6" type="number" step="0.1" name="cenovaHladinaCena[]" min="0" value="'.$result['CenovaHladinaCena'].'"> Kč</td>
     
     </tr>

  if (isset($_POST['ulozit'])) {

    var_dump($_POST);

有什么想法来获取数据插入?
下面是完整的代码

<form action="" method="post" autocomplete="off">
          <button type="submit" class="btn btn-primary" name="ulozit">Potvrdit</button>
      </div>
    </div>

    <!-- konec chlívečku info-->
    <!--tabulka přehled položek-->
    <!-- začátek divu grafů -->
    <div class="row col-12">
      <div class="col-12">
        <div class="card card-secondary">
          <div class="card-header">
            <div class="row">
              <div class="col-9">
                <h3 class="card-title"> Editace položek cenové hladiny <?php echo $nazevcenovahladina ?></h3>
              </div>

              <div class="col-3">

                <div class="float-sm-right">
                  <div id="tlacitkaExportu">
                  </div>
                </div>

              </div>


            </div>

          </div>

          <script>
            $(document).ready(function() {
              // DataTable
              var table = $('#example').DataTable({
                autoWidth: false,

                paging: false,
                ordering: true,
                info: false,
                dom: 'Brtip',

                buttons: [{
                    extend: 'copyHtml5',
                    text: '<i class="fa fa-file-pdf-o"></i>Kopírovat',
                    titleAttr: 'Kopírovat',
                    className: 'btn btn-default btn-sm',
                  },

                  {
                    extend: 'excelHtml5',
                    text: '<i class="fa fa-files-o"></i> Excel',
                    titleAttr: 'Excel',
                    title: "Položky cenové hladiny",
                    //message: "Any message for header inside the file. I am not able to put message in next row in excel file but you can use \n",
                    className: 'btn btn-default btn-sm',
                    exportOptions: {
                      columns: ':visible',
                      modifier: {
                        page: 'all'
                      }
                    },

                  }, {
                    extend: 'pdfHtml5',
                    text: '<i class="fa fa-file-pdf-o"></i> PDF',
                    titleAttr: 'PDF',
                    title: "Položky cenové hladiny",
                    className: 'btn btn-default btn-sm',
                    exportOptions: {
                      columns: ':visible'
                    }
                  },
                  {
                    extend: 'print',
                    text: '<i class="fa fa-print"></i> Tisk',
                    titleAttr: 'Tisk',
                    title: "Položky cenové hladiny",
                    className: 'btn btn-default btn-sm',
                    exportOptions: {
                      columns: ':visible'
                    }
                  }
                ]

              });


              table.buttons().container().appendTo("#tlacitkaExportu");

              // Setup - add a text input to each footer cell
              $('#example tfoot th').each(function() {
                var title = $('#example thead th').eq($(this).index()).text();

                $(this).html('<input ' +
                  ((title == "PLU") ? 'type="number" id="inputPlu"' : '') +
                  ((title == "EAN") ? 'type="number" id="inputEan"' : '') +
                  ((title == "Typ") ? 'type="text" id="inputTyp"' : '') +
                  ((title == "Název") ? 'type="text" id="inputNazev"' : '') +
                  ((title == "Skupina") ? 'type="text" id="inputSkupina"' : '') +
                  ((title == "Oddeleni") ? 'type="text" id="inputOddeleni"' : '') +
                  ((title == "Sklad") ? 'type="text" id="inputSklad"' : '') +
                  ((title == "Nákupní bez DPH") ? 'type="number" id="inputNakupniBezDph"' : '') +
                  ((title == "VNC") ? 'type="number" id="inputVnc"' : '') +
                  ((title == "Základní PC s DPH") ? 'type="number" id="inputPc"' : '') +
                  ((title == "Cena s DPH") ? 'type="number" class="col-md-6"' : '') +
                  '" placeholder = "' + title + ' ?" / > ');

              });

              // Apply the search
              table.columns().eq(0).each(function(colIdx) {
                $('input', table.column(colIdx).footer()).on('keyup change', function() {
                  table.column(colIdx)
                    .search(this.value)
                    .draw();
                });
              });

            });
          </script>
          <script type="text/javascript" src="https://cdn.datatables.net/buttons/1.6.1/js/dataTables.buttons.min.js"></script>
          <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
          <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/pdfmake.min.js"></script>
          <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/vfs_fonts.js"></script>
          <script type="text/javascript" src="https://cdn.datatables.net/buttons/1.6.1/js/buttons.html5.min.js"></script>
          <script type="text/javascript" src="https://cdn.datatables.net/buttons/1.6.1/js/buttons.print.min.js"></script>



          <div class="table-responsive p-0">
            <table id="example" class="table table-sm text-nowrap table-hover" style="width:100%">

              <thead>

                <tr>
                  <th>PLU</th>
                  <th>EAN</th>

                  <th>Název</th>
                  <th>Skupina</th>
                  <th>Oddělení</th>
                  <th>Sklad</th>
                  <th>Nákupní bez DPH</th>
                  <th>VNC</th>
                  <th>Základní PC s DPH</th>
                  <th title="Cena dané položky při aplikaci cenové hladiny.">Cena s DPH</th>

                </tr>
              </thead>

              <style>
                #inputPlu {
                  width: 60px;
                }

                #inputEan {
                  width: 120px;
                }

                #inputNakupniBezDph,
                #inputPc {
                  width: 90px;
                }

                #inputNazev {
                  width: 200px;
                }

                #inputSkupina {
                  width: 200px;
                }

                #inputVnc {
                  width: 90px;
                }
              </style>

              <tfoot>

                <tr>
                  <th>PLU</th>
                  <th>EAN</th>

                  <th>Název</th>
                  <th>Skupina</th>
                  <th>Oddělení</th>
                  <th>Sklad</th>

                  <th>Nákupní bez DPH</th>
                  <th>VNC</th>
                  <th>Základní PC s DPH</th>
                  <th title="Cena dané položky při aplikaci cenové hladiny.">Cena s DPH</th>

                </tr>
              </tfoot>

              <tbody>

                <?php
                if (!mysqli_num_rows($vysledek)) {
                  echo ('<div><p class="alert-error">Tento sklad / skupina nemá žádnou položku!</p></div>');
                } else {
                  # hlavička tabulky
                  while ($result = $vysledek->fetch_assoc()) {

                    
                    echo ('<tr>
      
      <td>' . $result['Plu'] . '<input type="hidden" name="ideckoSk[]" value="' . $result['Id_sklad_karta'] . '"></td>
      <td>' . $result['Ean'] . '</td>
     
      <td>' . $result['Nazev'] . '</a> </td>
      <td>' . $result['NazevSkupina'] . '</td>
      <td>' . $result['NazevOddeleni'] . '</td>
      <td>' . $result['NazevSklad'] . '<input type="hidden" name="ideckoSkladu[]" value="'.$result['Sklad_Id_sklad'].'"></td>
      
      <td>' . $osetreniTecky['Vnc'] . ' Kč</td>
      <td>' . $osetreniTecky['Nakupni_cena'] . ' Kč</td> 
     <td>' . $osetreniTecky['Cena_dph'] . ' Kč</td>
    
     <td><input class="col-md-6" type="number" step="0.1" name="cenovaHladinaCena[]" min="0" value="'.$result['CenovaHladinaCena'].'"> Kč</td>
     
     </tr>');
                  }
                }
                ?>

            </table>

            <div>

              </form>
            </div>
          </div>
        </div>
      </div>

      <?php

      //ULOŽENÍ DAT!!!!!!!!!!!!!!!!!!!!!!
      if (isset($_POST['ulozit'])) {

        var_dump($_POST);
        
        require "../config.php"; // Database connection

       

        //krok č. 2 insertuju nebo updatuju platné položky  
      
        foreach ($_POST['cenovaHladinaCena'] as $i => $cenovaHladinaCena) {

do something.....
fykwrbwg

fykwrbwg1#

你需要把提交按钮在订单提交后的要求。使用它如下。

<input type="submit" name="ulozit" >

相关问题