Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

105
Vistas
I am having issues updating my database from AJAX

I have shoppingbasket.php which has a HTML form, and is linked to incrementing.js I have plus and minus buttons which update the quantity of the item in the basket, however I am having issues updating my database (in PHPMyAdmin) so that the 'basket' table updates automatically when someone uses the plus or minus buttons.

Shoppingbasket.php includes:

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 includes:

$(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 includes:

<?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);
?>
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda