How to write a basket in php? Preferably the code with comments, or a link to the site where it is all described in detail. I searched the whole Internet, but I did not find it anywhere.

Closed due to the fact that the issue is too general for the participants of Regent , Vladimir Glinskikh , Aries , cyadvert , Visman on Oct 24 '15 at 5:44 .

Please correct the question so that it describes the specific problem with sufficient detail to determine the appropriate answer. Do not ask a few questions at once. See “How to ask a good question?” For clarification. If the question can be reformulated according to the rules set out in the certificate , edit it .

    2 answers 2

    I offer this option, it is workable and implement a newbie: Use ajax to add goods to the cart. Save all products in the current session, I don’t think there will be megabytes from huge lists with products, so we’ll mark the base for now or we’ll use it at the very end when buying. ajax: It is necessary to send it only the product identifier (if there is one) and provide for updating the dial (this is js) near the icon on the basket. php: do not forget to pull out from the session the number of goods and display near the basket. Also increase the list. Create a basket and product order page (final application form). Write php code to write the goods to the database where the goods manager will see the order. I will try to write something sane right here (without tests, but I think the point will become clear): ajax:

    javascript: function addToCorzin(_idTovara){ var s=document.createElement('script'); document.getElementsByTagName('head')[0].appendChild(s); s.src='http://urlsite/ajaxAddToCorzina.php?id='+_id+'&_sys='+new Date().getTime(); } php(ajaxAddToCorzina.php): session_start(); if(isset($_GET['id'])) if(isset($_SESSION['tovars'])) array_push($_SESSION['tovars'],$_GET['id']); else $_SESSION['tovars']=array($_GET['id']); print 'document.getElementById(\'corzinaCountTovarsLabel\').innerHTML='.count($_SESSION['tovars']).';'; php(рисуем корзинку где-нибудь - привожу с html): <div class="corzina"> Товаров:<span id="corzinaCountTovarsLabel"><?=isset($_SESSION['tovars'])?count($_SESSION['tovars']):0;?></span> ... </div> html(заказ товара): <div class="tovarClass"> <img src="tovar1url"/><input type="button" onclick="addToCorzin(<?=$fromBDData['id'];?>)"/> </div> 

    Further theory: On the checkout page, display the list of products (I hope it’s clear where to get the product identifiers), then display the fields for the form. Now what to do with the base or not, and what are the pros and cons: If you do in the base, you need at least a couple of tables (one for the details of ordering the goods, and the other is the association with your products and the current parameters of the customer). This approach will force you to make a window with orders in the admin panel. How to do it differently: without database. All that was ordered and all that the buyer had entered to himself was sent to the post office.

    PS: As soon as I decided to write this bit) This functionality can be implemented in one day, even for a beginner. I think at first fit. Why you don’t have to do anything complicated, because it’s because you don’t have payments through the site, it’s more complicated there and this approach will not work for you.

    • 7
      addToCorzin ... killCodeAuthorKotoriyTakPishetKod (); - Zowie

    Hmm ... And which functions of the basket do you need and what exactly does not work? I suspect that a good and convenient basket on php alone cannot be written, it is necessary to use AJAX. If you don’t know this technology, see the JsHttpRequest object on Dmitry Koterov’s website . It can make your life much easier, especially if used in conjunction with the jQuery library. But both JsHttpRequest and jQuery are based on JavaScript.