Jump to content

Alert message when quantity reaches max or min number


mik_se7

Recommended Posts

In my shopping cart i want an alert message when the maximum number of 5 for the item has been reached or ask them to delete the item if the press - when the item quantity is at 1.

 

i have it working in php:

    //add to quantity of item
    if (isset($_POST['itemadd'])){
    $additem = $_POST['additem'];
    $sqladd = "SELECT quantity FROM orders WHERE id = '$additem'";
    $query_add = mysqli_query($db_conx, $sqladd);
    while($row = mysqli_fetch_array($query_add, MYSQLI_ASSOC)){
        $itemqty = $row['quantity'];
        if ($itemqty < 5){
        $addqty = $itemqty + 1;
        $adding = "UPDATE orders SET quantity = '$addqty' WHERE id = '$additem'";
        $add_query = mysqli_query($db_conx, $adding);
        header('Location: http://www.quichlicious.co.uk/cart.php');
        //print $additem;
        exit();
        }
        else
        {
        $usemes = "You have reached maximum quantity";
        }
        }

But rather than display the message in a div i would like a javascript alert box to pop up, i tried the following code:

<script type="text/javascript">
function CheckQtyPlus(){
var qty = '<?php echo $qty; ?>';
alert("message here"+qty);
}
</script>

but i get the same quantity number for every item in the cart, i had this error with the php update but i got round that by querying sql to give me the quantity of an item by the items id.

can the same thing be done in javascript / ajax?

 

$qty by the way is referenced earlier in the script to get information for the cart table to display items.

 

thanks

Michael

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.