note 129308 added to function.session-start

From: Date: Mon, 04 Mar 2024 11:36:37 +0000
Subject: note 129308 added to function.session-start
Groups: php.notes 
Request: Send a blank email to php-notes+get-221232@lists.php.net to get a copy of this message
Un ejemplo de con sesion añadir productos a un carrito: <?php session_start(); $conexion=mysqli_connect('localhost', 'root', '', 'examen'); #accion $id=$_GET["id"]; $sql="SELECT * from productos where id = '$id'"; $result=mysqli_query($conexion,$sql); while($mostrar=mysqli_fetch_assoc($result)){ $_SESSION["carrito"][]=array( "id"=>$mostrar["id"], "categoria"=>$mostrar["categoria"], "color"=>$mostrar["color"], "marca"=>$mostrar["marca"], "precio"=>$mostrar["precio"] ); } if(isset($_GET["categoria"])){ $categoria=$_GET["categoria"]; header("Location: muestraProductos.php?categoria=$categoria"); } else{ header("Location: muestraProductos.php"); } ?> Y aqui comprobamos que se han añadido al carrito <?php #Carrito session_start(); if(isset($_SESSION["carrito"])){ ?> <table > <tr> <th>Categoría</th> <th>Color</th> <th>Marca</th> <th>Precio</th> </tr> <?php $total=0; foreach($_SESSION["carrito"] as $indice => $valor){ echo "<tr>"; echo "<td>".$valor["categoria"]."</td>"; echo "<td>".$valor["color"]."</td>"; echo "<td>".$valor["marca"]."</td>"; echo "<td>".$valor["precio"]."€</td>"; echo "</tr>"; $total = $total+$valor["precio"]; } echo $total."€ "; echo "<a href='pagar.php'><button type='button'>Pagar</button></a>"; } else{ echo "<h1>El carrito está vacío</h1>"; } ?> ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.13.131 (proxied: 195.53.92.167) ---- Manual Page -- https://php.net/manual/en/function.session-start.php Edit -- https://main.php.net/note/edit/129308 Del: integrated -- https://main.php.net/note/delete/129308/integrated Del: useless -- https://main.php.net/note/delete/129308/useless Del: bad code -- https://main.php.net/note/delete/129308/bad+code Del: spam -- https://main.php.net/note/delete/129308/spam Del: non-english -- https://main.php.net/note/delete/129308/non-english Del: in docs -- https://main.php.net/note/delete/129308/in+docs Del: other reasons-- https://main.php.net/note/delete/129308 Reject -- https://main.php.net/note/reject/129308 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#221232) next »