-
Notifications
You must be signed in to change notification settings - Fork 1
/
realizar_compra.php
42 lines (35 loc) · 1.03 KB
/
realizar_compra.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
<?php
require_once("conexion.php");
session_start();
if(isset($_SESSION['usuario_valido']))
{
$id = $_SESSION['usuario_valido'];
if(isset($_GET["id"]))
{
$id_articulo = $_GET["id"];
$cantidad = $_GET["cantidad"];
$query = "INSERT INTO usuario_articulo (id_usuario,id_articulo, cantidad) VALUES ($id, $id_articulo, $cantidad)";
mysqli_query($conexion, $query);
$query2 = "UPDATE articulo SET cantidad = cantidad - $cantidad WHERE id = $id_articulo";
mysqli_query($conexion,$query2);
}
else
{
foreach ($_SESSION['carro'] as $key => $value)
{
$cantidad = $value["cantidad"];
$existencia = $value["existencia"];
$query = "INSERT INTO usuario_articulo (id_usuario,id_articulo, cantidad) VALUES ($id, $key, $cantidad)";
mysqli_query($conexion, $query);
$query2 = "UPDATE articulo SET cantidad = ($existencia - $cantidad) WHERE id = $key";
mysqli_query($conexion,$query2);
}
unset($_SESSION['carro']);
}
echo "Gracias por su compra";
}
else
{
return;
}
?>