Answer the question
In order to leave comments, you need to log in
How to send rollback json from php to ajax?
There is a product card:
<a href="./cart.php?product_id=<?=$products['id']?> data-id="<?=$products['id']?>"" class="buy">Купить</a>
<?php
session_start();
include 'include/database.php';
if (!isset($_SESSION['cart'])) {
$_SESSION['cart'] = array();
}
$res_data = array();
$product_id = isset($_GET['product_id']) ? $_GET['product_id'] : null;
if (isset($_SESSION['cart']) && array_search($product_id, $_SESSION['cart']) === false) {
$_SESSION['cart'][] = $product_id;
$res_data['count'] = count($_SESSION['cart']);
$res_data['success'] = 1;
}else {
$res_data['success'] = 0;
}
json_encode($res_data);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question