Jump to content

Alert message when quantity reaches max or min number


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;
        $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);

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.




Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • 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.