Tengo shoppingbasket.php que tiene un formulario HTML y está vinculado a incrementing.js Tengo botones más y menos que actualizan la cantidad del artículo en la cesta, sin embargo, tengo problemas para actualizar mi base de datos (en PHPMyAdmin) para que el La tabla 'cesta' se actualiza automáticamente cuando alguien usa los botones más o menos.
Cesta de la compra.php incluye:
Print '<div id="list_item"> <img src="Images/' . $img . '"> <div id="rightside"> <a href="singlepage.php?subject=' . $product_id . '">' . $name . '</a><br> <p>' . $subtitle . '</p><br> <form id="quantity" method="POST" action=""> <div class="numbers-row"> <input type = "text" id="' . $product_id . '" value="' . $quantity . '"> </div> </form> </div> </div>';Incrementing.js incluye:
$(function() { $(".numbers-row").append('<div class="inc button">+</div><div class="dec button">-</div>'); $(".button").on("click", function() { var $button = $(this); var oldValue = $button.parent().find("input").val(); if ($button.text() == "+") { var quantity = parseFloat(oldValue) + 1; } else { // Don't allow decrementing below zero if (oldValue > 0) { var quantity = parseFloat(oldValue) - 1; } else { quantity = 0; } } }); var pid = $button.attr("id"); $.ajax({ type: "POST", url: "basket2table.php", data: { pid : pid, quantity: quantity, }, success: function() { $button.parent().find("input").val(quantity); } }); });Basket2table.php incluye:
<?php include("dbconnect.php"); if(isset($_POST['quantity'])) { $quantity = $_POST['quantity']; } if(isset($_POST['pid'])){ $pid = $_POST['pid']; } $sql_query = "UPDATE Basket SET quantity='$quantity' WHERE product_ID='$pid' "; $result = $db-> query($sql_query); ?>