1
Good evening guys, my goal is when go back to the products page, and go back to the cart, keeping the session variable and also fill the cart page with more products every time the array gets a new one, as it is generating a single product. Thanks in advance. Follow the code below:
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<?php session_start();?>
<html>
<head lang="pt-br">
<meta charset="UTF-8">
<title>E-Commerce</title>
</head>
<body>
<h1>Produtos</h1>
<ul>
<li><a href="ipad.php">Ipad</a></li>
<li><a href="playstation.php">Playstation</a></li>
<li><a href="xbox.php">Xbox</a></li>
</ul>
<br/>
<a href="carrinho.php">Ver Carrinho</a>
<?php
// put your code here
?>
</body>
</html>
Now the cart page.php:
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<?php session_start(); ?>
<html>
<head>
<meta charset="UTF-8">
<title>E-Commerce</title>
</head>
<body>
<h1>Carrinho de Compras</h1>
<?php
$_SESSION['valor'] = array();
array_push($_SESSION['valor'], $_GET['valor']);
?>
<?php foreach($_SESSION['valor'] as $list):?>
<ul>
<li><?php echo $list;?></li>
</ul>
<?php endforeach; ?>
<a href="produtos.php">Continuar Comprando</a>
<br/>
<br/>
<a href="#">Efetuar Pagamentos</a>
</body>
</html>
And the product page, which differs from the others only in the product name passed by the url,
!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<?php session_start();?>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<title>E-Commerce</title>
</head>
<body>
<h1>IPAD</h1>
<ul>
<li><a href="carrinho.php?valor=ipad">Colocar no Carrinho</li>
<li><a href="carrinho.php">Ver Carrinho</a></li>
<li><a href="produtos.php">Produtos</a></li>
</ul>
<?php
// put your code here
?>
</body>
</html>
What I’m not getting is when I go out and go back to the cart continue viewing the product, and present more products in the cart page. It was worth it !
So I already did, but my code keeps giving the problem of: Notice: Undefined index: value in C: xampp htdocs Project_phpsessions carrinho.php on line 11 // When I go back to Carrinho and is not adding more than one product.
– Thiago
Where is the line 11??? I think I already know.
– Lollipop
array_push($_SESSION['cart'], $_GET['value']); // Is this line.
– Thiago
So I passed $_GET['value'] to $variable and it’s not like that either rsr There’s a way to get for $_GET ?
– Thiago
Let’s go continue this discussion in chat.
– Lollipop
Still not understood, got confused, the isset add here, solved that problem, now, to leave the page and keep the value not.
– Thiago
value is kept in $_SESSION['cart']
– Lollipop
You have to start session_start();, before
– Lollipop
@Thiago, nothing yet?
– Lollipop