Mantener el Valor de un arreglo al hacer Post
Publicado por Patricio Romero (2 intervenciones) el 22/07/2015 02:09:44
Estimados
Necesito mantener los valores en un array cada vez que proceso un formulario con post, o no se si habra otra forma de trabajar. la indea es a traves de un formulario agragando elementos que se ingresan a un array para mostrarse e indicar su suma total.
el codigo es el sgte.:
agradezco su ayuda
atte
Necesito mantener los valores en un array cada vez que proceso un formulario con post, o no se si habra otra forma de trabajar. la indea es a traves de un formulario agragando elementos que se ingresan a un array para mostrarse e indicar su suma total.
el codigo es el sgte.:
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
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>INGRESO DE ARTICULOS</title>
</head>
<body bgcolor="#D2EBF7" style="font-family: Tahoma;">
<form name="form1" method="post" action="agregararticulo.php">
<table width="282">
<tr>
<td width="74">Artículo</td>
<td width="182">
<input type="text" name="articulo" size="30" maxlength="30">
</td>
</tr>
<tr>
<td>Precio</td>
<td>
<input name="precio" type="text" id="precio" size="10" maxlength="5">
</td>
</tr>
<tr>
<td>Cantidad</td>
<td>
<input type="text" name="cantidad" size="10" maxlength="3">
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="enviar" value="Enviar" id="enviar">
</td>
</tr>
</table>
</form>
<?php
$articulo = $_POST["articulo"];
$rec["articulo"] = $_POST["articulo"];
$rec["precio"] = $_POST["precio"];
$rec["cantidad"] = $_POST["cantidad"];
$rec["subtotal"] = $rec["precio"] * $rec["cantidad"];
$_POST["carrito"][$articulo] = $rec;
?>
<table width='447' border='1'>
<tr>
<th width="188">Articulo</th>
<th width="73">Precio</th>
<th width="65">Cant.</th>
<th width="93">Subtotal</th>
</tr>
<?php foreach ( $_POST["carrito"] as $rec ) { ?>
<tr>
<td><?php echo($rec["articulo"]) ?></td>
<td><?php echo($rec["precio"]) ?></td>
<td><?php echo($rec["cantidad"]) ?></td>
<td><?php echo($rec["subtotal"]) ?></td>
</tr>
<?php } ?>
</table>
</body>
</html>
agradezco su ayuda
atte
Valora esta pregunta
0