How insert values from client page to database by use custom module Help me pls. I need update database table in Drupal 8. Exemple on image.


When user click on button "ADD PRODUCT TO CART", cart value must update on page (its not a problem), cart value and user ip-address must be write to database.
Im try use ajax for this logic, but values do not write to database.
Js code:

jQuery('.cart button').on('click', function () {
var price = jQuery('.price').text();
var priceValue = parseInt(price.substring(0, price.length - 1));
var cart = jQuery('#cart');
var cartValue = parseInt(cart.text().substring(0, cart.text().length - 1));
cart.text(cartValue + priceValue + '$');

jQuery.getJSON("http://jsonip.com/?callback=?", function (data) {
    var ip = data.ip.toString();

    jQuery.ajax({
        type: "POST",
        url: "../myupdate.php",
        data: ["ip="+ip, "cart="+jQuery('#cart').text()]
    }).done(function () {
        console.log('done');
    }).error(function () {
        console.log('error');
    });

});


});

php code:

&lt;?php
$ip = $_POST[ip];
$cart = $_POST[cart];
db_insert('abweb')
    -&gt;fields(array('ip' =&gt; $ip, 'product' =&gt; 'some product', 'price' =&gt; $cart))
    -&gt;execute();


This logic is implemented in the custom module. HELP PLS!!
Here is way to do this. use line item type and create your filed.  Hook_commerce_cart_product_add() call in custom module.

  function mymodule_commerce_cart_product_add($order, $product, $quantity, $line_item) {

         $commerce_line_item = commerce_line_item_load($line_item-&gt;line_item_id);

         $field_main = $product-&gt;field_main['und']['0']['value'];

         $line_item-&gt;field_update[LANGUAGE_NONE][0]['value'] = $field_main;

         commerce_line_item_save($line_item);
     }


When user click on button "ADD PRODUCT TO CART", cart value add/update your commerce line item field.