PHP - Duda "session_register" en "Tienda Online"

 
Vista:

Duda "session_register" en "Tienda Online"

Publicado por manolito74 (3 intervenciones) el 02/12/2019 22:20:46
Hola:

Tengo un Programa de una "Tienda Online".

El Programa se compone de 3 partes:

- formulario.php

- confirmar.php

- productos.php

Pues bien, el problema-duda que tengo es con esta línea del Fichero "productos.php":

1
session_register('pedido');

Si la pongo me aparece el error:

Fatal error: Uncaught Error: Call to undefined function session_register() in T:\XAMPP\htdocs\MIS-EJERCICIOS\TIENDA\productos.php:11 Stack trace: #0 {main} thrown in T:\XAMPP\htdocs\MIS-EJERCICIOS\TIENDA\productos.php on line 11

¿Alguna idea?

Os pongo debajo todo el Código para que quede más claro.

Gracias & Saludetes. ;-)


FORMULARIO.PHP

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
<?php
	session_start();
	session_destroy();
?>
 
 
<html>
 
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    </head>
 
    <body>
 
        <h1>Bienvenido a la tienda</h1>
 
        <form action="productos.php" method="post">
 
                Ingrese su nombre : <input name="nombre" type="text">
 
                <input name="ingresar" type="submit" value="ingresar">
 
        </form>
 
    </body>
 
</html>



PRODUCTOS.PHP

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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php
 
session_start(); //Inicio sesion
 
if (isset($_POST['nombre']))
{
    $nombre = $_POST['nombre'];
    $_SESSION['usuario'] = $nombre;		//Guardo el nombre del usuario en sesion
    session_register('pedido');
 
}
 
if (isset($_POST['agregar']))						//Si se envió el primer formulario
{
    $claves = array_keys($_POST);
    $producto = $claves[1];
 
    if (!is_array($_SESSION['pedido'])) //Si no es un array
    {
        $_SESSION['pedido'] = array();
    }
 
    if(array_key_exists("$producto", $_SESSION['pedido']))
    {
            $cantidad = $_SESSION['pedido']["$producto"];
            $_SESSION['pedido']["$producto"] = ++$cantidad;
    }
    else
    {
            $_SESSION['pedido']["$producto"] = 1;
    }
}
 
if(isset($_GET['quitar']))			//Si se envió el segundo formulario
{
        $claves = array_keys($_GET);
        $producto = $claves[1];
        unset($_SESSION['pedido'][$producto]); //Eliminar la posicion del arreglo
}
 
echo "Bienvenido : ".$_SESSION['usuario'];
 
?>
 
 
 
<html>
 
	<head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	</head>
 
	<body>
 
        <form action="productos.php" method="post">
            <input type="hidden" name="agregar">
 
            <table border="1">
 
                <tr>
                    <td width="150">
                        Producto: <b>TV</b><br>
                        Descripcion: <b>31"</b><br>
                        Precio: <b>1500000</b><br>
                        <input type="submit" name="TV" id="button" value="Anadir al carrito">
                    </td>
                    <td width="150">
                        Producto: <b>DVD</b><br>
                        Descripcion: <b>Negro</b><br>
                        Precio: <b>200000</b><br>
                        <input type="submit" name="DVD" id="button2" value="Anadir al carrito">
                    </td>
                    <td width="150">
                        Producto: <b>MP4</b><br>
                        Descripcion: <b>4GB</b><br>
                        Precio: <b>150000</b><br>
                        <input type="submit" name="MP4" id="button3" value="Anadir al carrito">
                    </td>
                </tr>
                <tr>
                    <td>
                        Producto: <b>Laptop</b><br>
                        Descripcion: <b>12"</b><br>
                        Precio: <b>1500000</b><br>
                        <input type="submit" name="Laptop" id="button3" value="Anadir al carrito">
                    </td>
                    <td>
                        Producto: <b>MP3</b><br>
                        Descripcion: <b>2GB</b><br>
                        Precio: <b>100000</b><br>
                        <input type="submit" name="MP3" id="button3" value="Anadir al carrito">
                    </td>
                    <td>
                        Producto: <b>Camara</b><br>
                        Descripcion: <b>12Mpx</b><br>
                        Precio: <b>250000</b><br>
                        <input type="submit" name="Camara" id="button3" value="Anadir al carrito">
                    </td>
                </tr>
 
                <tr>
                    <td>
                        Producto: <b>Celular</b><br>
                        Descripcion: <b>Negro</b><br>
                        Precio: <b>200000</b><br>
                        <input type="submit" name="Celular" id="button3" value="Anadir al carrito">
                    </td>
                    <td>
                        Producto: <b>PSP</b><br>
                        Descripcion: <b>Gris</b><br>
                        Precio: <b>500000</b><br>
                        <input type="submit" name="PSP" id="button3" value="Anadir al carrito">
                    </td>
                    <td>
                        Producto: <b>Impresora</b><br>
                        Descripcion: <b>Multifuncional</b><br>
                        Precio: <b>300000</b><br>
                        <input type="submit" name="Impresora" id="button3" value="Anadir al carrito">
                    </td>
                </tr>
 
            </table>
 
        </form>
 
 
        <form action="productos.php" method="get">
 
            <h1>En el carrito de compras tiene los siguientes productos</h1>
 
            <input type="hidden" name="quitar">
 
            <?php
 
                if (!empty($_SESSION['pedido']))		//Si hay productos en el carrito
                {
                    foreach ($_SESSION['pedido']   as   $prod => $unidades)
                    {
                        echo "$unidades unidades del producto $prod";
                        echo "<input type='Submit' name='$prod' value='Quitar'><br>";
                    }
                }
            ?>
 
        </form>
 
 
        <form action="confirmar.php" method="post">
 
            <input type='Submit' name='Comprar' value="Confirmar compra">
 
        </form>
 
 
	</body>
 
</html>


CONFIRMAR.PHP[

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
 
    session_start();
 
    echo "<h1 align='center'>FELICIDADES</h1> <h2 align='center'>acaba de comprar</h2>";
 
    foreach ($_SESSION['pedido']    as   $prod => $unidades)
    {
 
        echo "<p align='center'>$unidades $prod</p>";
 
    }
 
?>
 
 
<h2 align='center'>Gracias por su compra</h2>
 
<h2>Vuelva pronto</h2>
 
<a href="formulario.php">TERMINAR</a>
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

Duda "session_register" en "Tienda Online"

Publicado por manolito74 (3 intervenciones) el 03/12/2019 21:44:22
Hola.

¿Y qué modificación tendría que hacer en el Programa para que funcione bien?

Gracias & Saludetes. ;-)
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
Imágen de perfil de joel
Val: 3.828
Oro
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

Duda "session_register" en "Tienda Online"

Publicado por joel (1269 intervenciones) el 05/12/2019 08:26:56
Quita el session_register que tienes, no se muy bien que hace ahí... creo que te funcionara sin esa linea.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar