Answer the question
In order to leave comments, you need to log in
How to output data from Cookie to a table?
Hello everyone, I have this question....
There is a file, komp.php where are the goods that are taken from the database
<?php
$r = mysqli_query($conn, "SELECT * FROM `komputer`") or die($conn );
while ($row = mysqli_fetch_assoc($r)) {
if($row['category'] == 1){
?>
<?php echo $row['name'] ?>
<?php echo' ' ?>
- ->
<?php echo $row['descriptions'] ?>
<?php echo $row ['price'] ?>
<?php echo 'order' ?>
More details
<?php
}
}
?>
When clicking on the button, script fires:
$(".add-cart").on("click",
data: {
product_id: $(this).attr('data-id')
},
success: function(data){
alert("Item added to cart")
}
});
});
Then everything goes to the handler:
<?php
$product_id = $_POST["product_id"];
$cart = isset($_COOKIE['the_cookie']) ? json_decode($_COOKIE['the_cookie'], true) : [] ;
if (!isset($cart[$product_id])) {
$cart[$product_id] = 1;
} else {
$cart[$product_id] = $cart[$product_id] + 1;
}
setcookie('the_cookie', json_encode($cart), time()+100000);
And displays these cookies on the page:
<?php
$cook = $_COOKIE['the_cookie'];
echo $cook;
How can I make it appear in the form of a table, in finished form it should be a shopping cart
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