PHP - Tec. Ingenieria en Sistemas Informaticos

 
Vista:

Tec. Ingenieria en Sistemas Informaticos

Publicado por Carlos Franco (2 intervenciones) el 20/03/2017 19:04:35
ME PUEDEN AYUDAR A ENCONTRAR LOS ERRORES DE ESTE CODIGO POR FAVOR...

SALUDOS, MUCHAS GRACIAS DE ANTE MANO


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
session_start();
?>
<html>
<head>
<title>Carrito de Compras </title>
<meta charset="utf-8">
</head>
<body>
 
<form action="#" method="POST"> <br>
Producto:<input type="text" name="txtproduc"> <br>
Cantidad:<input type="text" name="txtcantidad"><br>
Precio:<input type="text" name="txtprecio">  <br>
<input type="submit" name="btnregistrar" value="registrar"> <br>
<input type="submit" name="btnMostrar" value="mostrar"> <br>
<input type="submit" name="btnReiniciar" value="Reiniciar"> <br>
<input type="submit" name="btnCalcular" vaciar="Calcular"> <br>
</form>
 
<?php
 
if(isset($_REQUEST["btnregistrar"]))
{
$Producto=$_REQUEST["txtproduc"];
$cantidad=$_REQUEST["txtcantidad"];
$precio=$_REQUEST["txtprecio"];
$total=0;
 
$_SESSION["carrito"][$producto]["cantidad"]=$cantidad;
$_SESSION["carrito"][$producto]["precio"]=$precio;
}
 
if(isset($_REQUEST["btnMostrar"]))
{
	foreach ($_SESSION["carrito"] as $indice =>$arreglo)
	 {
		print "Del producto: ".$indice."<br>";
		foreach ($arreglo as $key => $value)
		 {
			print($key ." = ". $value . "<br>");
		}
	}
}
 
if (isset($_REQUEST["btnCalcular"]))
{
	foreach ($_REQUEST["carrito"] as $indice => $arreglo)
	 {
 
		$total = $total + ($arreglo["cantidad"] * $arreglo["precio"]);
	}
}
 
print "El total a pagar es $ ".$total;
 
if(isset($_REQUEST["btnReiniciar"]))
{
 
	session_destroy();
}
 
?>
 
</body>
</html>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil

Tec. Ingenieria en Sistemas Informaticos

Publicado por Victor Fcp. (12 intervenciones) el 20/03/2017 22:00:38
De entrada estás comprobando con isset $_request, y cada vez que le envies el formulario se envia, deberías de cambiarlo por :
1
2
3
4
if(!empty($_REQUEST['btnregistrar'] && $_REQUEST['btnregistrar'] == 'registrar')
if(!empty($_REQUEST['btnMostrar'] && $_REQUEST['btnMostrar'] == 'mostrar')
if(!empty($_REQUEST['btnReiniciar'] && $_REQUEST['btnReiniciar'] == 'Reiniciar')
if(!empty($_REQUEST['btnCalcular'] && $_REQUEST['btnCalcular'] == 'Calcular')
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Tec. Ingenieria en Sistemas Informaticos

Publicado por Carlos Franco (2 intervenciones) el 21/03/2017 16:17:31
Muchas Gracias en este momento compruebo
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar