简体   繁体   中英

PHP and MySQL help for Shopping Cart

I have gotten stuck in a Homework Project where I need to incorporate a Online E-Commerce Store onto my HTML and CSS Barebones Web Page.

I'm trying to get the Add To Cart Button to display and this is the code I have but it is not displaying at all.

<script>
        $(document).ready(function(){
        // add to cart button listener
        $('.add-to-cart-form').on('submit', function(){

            // info is in the table / single product layout
            var id = $(this).find('.product-id').text();
            var quantity = $(this).find('.cart-quantity').val();

            // redirect to add_to_cart.php, with parameter values to process the request
            window.location.href = "add_to_cart.php?id=" + id + "&quantity=" + quantity;
            return false;
        });
    });
</script>

This is one of the subpages, not the main page.

I'm trying to get the idea from this link : https://www.codeofaninja.com/2015/08/simple-php-mysql-shopping-cart-tutorial.html .

I'm trying to get forward but I can't even get their example to work on my project.

I keep on getting the same webpage as before and none of their changes are showing up.

Please don't hesitate to ask for additional details.

This is my first time on Stack Overflow. I'm a beginner on making websites. Any help would be appreciated. I need to have this done by Friday.

Thank you all in Advance.

The current code only attaches a JS function to the 'Add to Cart' button. But you haven't created one yet.

Further down on that tutorial webpage it has a section to actually display the button called "10.10 Render 'Cart' button" This is probably the least of the code amount needed for it to work:

<form class='add-to-cart-form'>
    <div class='product-id'>
        <?php echo $id; ?>
    </div>
    <div>Quantity:</div>
    <input type='number' class='cart-quantity' value='1' min='1' />
    <button type='submit'>
         Add to cart
    </button>
</form>

Taken from https://www.codeofaninja.com/2015/08/simple-php-mysql-shopping-cart-tutorial.html

You can put this section into your sub page where the script is also located.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM