title: I have to output my data from DataBase and also copy all inputs from form to send them to myself, including real-time multiplying weight*pcs
body: <p>I've got some code where I have to <strong>input my contact data</strong> from client, and  <strong>output data from MySQL database which creates new rows in table</strong></p>
  <p>Also there's additional function which has to be inside the code - but I've no idea how to handle this problem. I have to count the amount of <strong>element pieces x their weight</strong> in real-time to show the client the <strong>total weight the order is going to have.</strong></p>
  <p>The problem is I don't know how to make the client see it whenever they change the value of <strong>Pieces</strong> in <code>&lt;input&gt;</code>.</p>
  <p>Lastly, the data from the form and table has to be sent to employee via email.</p>
  <p><strong>PHP Code:</strong></p>
  <pre><code> &lt;html&gt;
    &lt;head&gt;
      &lt;meta charset=&quot;utf-8&quot; /&gt;
      &lt;meta name=&quot;calculator&quot; content=&quot;width=device-width, initial-scale=1&quot;/&gt;
          &lt;title&gt;Test&lt;/title&gt;
          &lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot; &gt;
    &lt;/head&gt;
  
      &lt;body&gt;
          &lt;!-- including calc.php file which contains all variables --&gt;
          &lt;?php include 'calc.php'; ?&gt;
          &lt;!-- Printing the form --&gt;
      &lt;form method=&quot;post&quot; action=&quot;sendform.php&quot;&gt;&lt;br&gt;
      
       &lt;center&gt;
       &lt;h1&gt;TEST&lt;/h1&gt;
          &lt;input id=&quot;Name&quot; type=&quot;text&quot; placeholder=&quot;&lt;?= $form['FIRMA']; ?&gt;&quot; class=&quot;form-contact&quot; required&gt;&lt;br&gt;
           &lt;input id=&quot;Adres&quot; type=&quot;text&quot; placeholder=&quot;&lt;?= $form['ADRES']; ?&gt;&quot; class=&quot;form-contact&quot; required&gt;&lt;br&gt;
            &lt;input id=&quot;Email&quot; type=&quot;email&quot; placeholder=&quot;&lt;?= $form['EMAIL']; ?&gt;&quot; class=&quot;form-contact&quot; required&gt;&lt;br&gt;
             &lt;input id=&quot;Country&quot; type=&quot;text&quot; placeholder=&quot;&lt;?= $form['COUNTRY']; ?&gt;&quot; class=&quot;form-contact&quot; value=&quot;&quot; size=&quot;1&quot; pattern=&quot;[0-9]{2}&quot; maxlength=&quot;2&quot; required&gt;
              &lt;input id=&quot;Phone&quot; type=&quot;text&quot; placeholder=&quot;&lt;?= $form['PHONE']; ?&gt;&quot; class=&quot;form-contact&quot; pattern=&quot;[0-9]{9}&quot; maxlength=&quot;9&quot; required&gt;
              &lt;br&gt;
              
          &lt;!-- Printing out the table --&gt;
          
    &lt;table class=&quot;table-responsive&quot; border=&quot;1&quot;&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;&lt;?= $form['PRODUCTS']; ?&gt;&lt;/th&gt;
              &lt;th&gt;&lt;?= $form['CATALOG']; ?&gt;&lt;/th&gt;
              &lt;th&gt;&lt;?= $form['DESC']; ?&gt;&lt;/th&gt;
              &lt;th&gt;&lt;?= $form['WEIGHT']; ?&gt;&lt;/th&gt;
              &lt;th&gt;&lt;?= $form['TWEIGHT']; ?&gt;&lt;/th&gt;
          &lt;br&gt;
          &lt;/tr&gt;
  
      &lt;/thead&gt;
        &lt;tbody&gt;
        
        &lt;?php
              # Database connection
                  $dbhost = &quot;localhost&quot;;
                  $dbuser = &quot;root&quot;;
                  $dbpass = &quot;1234&quot;;
                  $dbname = &quot;data&quot;;
  
                  $connection = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
                  if ($connection-&gt;connect_error) {
                      die(&quot;Connection failed: &quot; . $connection-&gt;connect_error);
                  }
                  #echo &quot;Connection successfull!&quot;;
                  
                  # Questions for Database
                  $sql = 'SELECT * FROM `elements`';
                  $result = mysqli_query($connection, $sql);
                  
                      if (mysqli_num_rows($result) &gt; 0) {
                          //output data each row
                          while($row = mysqli_fetch_assoc($result)) {
                              echo &quot;&lt;tr&gt;&lt;td&gt;&quot;.'&lt;input class=&quot;pcs-input&quot; min=0 maxlength=&quot;3&quot; value=0 size=&quot;2px&quot; style=&quot;background-color: white;&quot; name=&quot;inputs[]&quot;&gt;';
                              echo &quot;&lt;/td&gt;&lt;td&gt;Nr. &quot;  . $row[&quot;pcode&quot;] . &quot;&lt;/td&gt;&lt;td&gt; &quot; . $row[&quot;fullname&quot;]. &quot;&lt;/td&gt;&lt;td&gt; &quot; . $row[&quot;weight&quot;] . &quot;kg&lt;/td&gt;&lt;td&gt;&lt;div id='sumWeight'&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&quot;;
                              
                          }
                          } else {
                          echo &quot;0 Results&quot;;
                      }
  
                  mysqli_close($connection);
        ?&gt;
  
        &lt;/tbody&gt;
      &lt;/table&gt;
          &lt;!-- Counting all needed atributes --&gt;
              &lt;div id=&quot;totalWeight&quot;&gt;totalWeight&lt;/div&gt;
          &lt;!-- Submit btn --&gt;
          &lt;br&gt;&lt;button name=&quot;submit&quot; type=&quot;submit&quot; value=&quot;Send&quot; class=&quot;form-button&quot;&gt;Send&lt;/button&gt;
          &lt;/center&gt;
      &lt;/form&gt;
          
      &lt;/body&gt;
      
    &lt;/html&gt;
  </code></pre>
  <h2>JavaScript Code</h2>
  <pre><code>    &lt;script type=&quot;text/javascript&quot;&gt;
      document.addEventListener(function()
      input.OnChange = calculateForm();
      function calculateForm() {
          var totalWeight = 0;
          $(&quot;.pcs-input&quot;).each(function () {
              var pcs = parseInt($(this).val());
              if (pcs &lt; 0) {
                  pcs = 0;
              } else {
                  var weight = parseFloat($(this).data('weight'));
                  var sumWeight = pcs * weight;
                  totalWeight += sumWeight;
              }
          });
         document.write(totalWeight.toFixed(2) + ' kg');
        }
      )};
      &lt;/script&gt;
  </code></pre>
  <h2>Updated</h2>
  <p><strong>Well it doesn't work again, no errors, just doesn't multiply</strong>
  I think the problem might be with transporting data from table/database into the variable, any solution?</p>
  <pre><code> &lt;?php
              # Database connection
                  $dbhost = &quot;localhost&quot;;
                  $dbuser = &quot;root&quot;;
                  $dbpass = &quot;1234&quot;;
                  $dbname = &quot;data&quot;;
  
                  $connection = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
                  if ($connection-&gt;connect_error) {
                      die(&quot;Connection failed: &quot; . $connection-&gt;connect_error);
                  }
                  #echo &quot;Connection successfull!&quot;;
                  
                  # Questions for Database
                  $sql = 'SELECT * FROM `elements`';
                  $result = mysqli_query($connection, $sql);
                  
                      if (mysqli_num_rows($result) &gt; 0) {
                          //output data each row
                          while($row = mysqli_fetch_assoc($result)) {
                              echo &quot;&lt;tr&gt;&lt;td&gt;&quot;.&quot;&lt;input type='number' class='pcs-input' id='inputs' data-weight=&quot;.$row[&quot;weight&quot;];
                              echo &quot;&gt;&lt;/input&gt;&quot;;
                              # echo &quot;&lt;tr&gt;&lt;td&gt;&quot;.$row[&quot;id&quot;].'';
                              echo &quot;&lt;/td&gt;&lt;td&gt;Nr. &quot;  . $row[&quot;pcode&quot;] . &quot;&lt;/td&gt;&lt;td&gt; &quot; . $row[&quot;fullname&quot;]. &quot;&lt;/td&gt;&lt;td&gt; &quot; . $row[&quot;weight&quot;] . &quot;kg&lt;/td&gt;&lt;td&gt;&lt;div id='sum-Weight2'&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&quot;;
                              
                          }
                        } else {
                          echo &quot;0 Results&quot;;
                      }
          #Declaring JavaScript Code inside PHP
                  mysqli_close($connection);
        ?&gt;
  
        &lt;/tbody&gt;
      &lt;/table&gt;
      &lt;script type=&quot;text/javascript&quot;&gt;
      function calculateForm() {
          var totalWeight = 0;
          $(&quot;.pcs-input&quot;).each(function () {
              var pcs = parseInt($(this).val());
              if (pcs &lt; 0) {
                  pcs = 0;
              } else {
                  var weight = parseFloat($(this).data('weight'));
                  var sumWeight = pcs * weight;
                  $(this).parent().parent().find('.sum-weight2').html(sumWeight.toFixed(2) + ' kg');
                  totalWeight += sumWeight;
              };
         $('.totalGewicht').html(totalWeight.toFixed(2) + ' kg');
        }
      )};
      &lt;/script&gt;
          &lt;!-- Counting all needed atributes --&gt;
              &lt;div id=&quot;totalWeight&quot;&gt;&lt;/div&gt;
          &lt;!-- Submit btn --&gt;
          &lt;br&gt;&lt;button name=&quot;submit&quot; type=&quot;submit&quot; value=&quot;Send&quot; class=&quot;form-button&quot;&gt;Send&lt;/button&gt;
          &lt;/center&gt;
      &lt;/form&gt;
  </code></pre>