SQL
This commit is contained in:
parent
3439474297
commit
2f48dbdb45
|
|
@ -9,13 +9,16 @@
|
|||
</head>
|
||||
|
||||
<body>
|
||||
<h2>Iniciar Sesión</h2>
|
||||
<?php if (isset($_GET['mensaje'])) echo "<p>" . $_GET['mensaje'] . "</p>";?>
|
||||
<?php if (isset($mensaje_error)) echo "<p>$mensaje_error</p>"; ?>
|
||||
<form action="" method="post">
|
||||
|
||||
|
||||
<label for="email">Correo Electronico:</label>
|
||||
<input type="text" id="email" name="email" required>
|
||||
|
||||
<label for="password">Contraseña:</label>
|
||||
<input type="text" id="password" name="password" required>
|
||||
<input type="password" id="password" name="password" required>
|
||||
|
||||
<input type="submit" value="Enviar">
|
||||
</form>
|
||||
|
|
@ -37,7 +40,6 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|||
exit("Error de conexión: " . mysqli_connect_error());
|
||||
}
|
||||
|
||||
|
||||
$consulta_sql = "SELECT * FROM usuarios WHERE correo_electronico = '$email'";
|
||||
$resultado = mysqli_query($conexion, $consulta_sql);
|
||||
|
||||
|
|
@ -46,7 +48,7 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|||
if (password_verify($password, $usuario['contraseña'])) {
|
||||
echo "Correcto";
|
||||
session_start();
|
||||
$_SESSION['email'] = $email;
|
||||
$_SESSION['cliente_id'] = $usuario['cliente_id'];
|
||||
header("Location: realizar_pedido.php");
|
||||
exit();
|
||||
} else {
|
||||
|
|
|
|||
102
Practicas/Practicas_SQL/ejercicios/tienda/realizar_pedido.php
Normal file
102
Practicas/Practicas_SQL/ejercicios/tienda/realizar_pedido.php
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
<?php
|
||||
// Comprobamos si existe la sesión
|
||||
session_start();
|
||||
if (!isset($_SESSION['cliente_id'])) {
|
||||
// En caso contrario devolvemos a la página login.php
|
||||
header('Location: login.php');
|
||||
die();
|
||||
}
|
||||
|
||||
$cliente_id = $_SESSION['cliente_id'];
|
||||
$nombre_servidor = "localhost";
|
||||
$nombre_usuario = "root";
|
||||
$contraseña = "Logomark8";
|
||||
$nombre_base_datos = "tienda";
|
||||
|
||||
mysqli_report(MYSQLI_REPORT_OFF);
|
||||
$conexion = mysqli_connect($nombre_servidor, $nombre_usuario, $contraseña, $nombre_base_datos);
|
||||
if (!$conexion) {
|
||||
exit("Error de conexión: " . mysqli_connect_error());
|
||||
}
|
||||
|
||||
$consulta_sql = "SELECT * FROM productos";
|
||||
$resultado = mysqli_query($conexion, $consulta_sql);
|
||||
if (!$resultado) {
|
||||
exit("Error al ejecutar la consulta: " . mysqli_error($conexion));
|
||||
}
|
||||
|
||||
$productos = mysqli_fetch_all($resultado, MYSQLI_ASSOC);
|
||||
|
||||
mysqli_free_result($resultado);
|
||||
mysqli_close($conexion);
|
||||
?>
|
||||
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="stylesheet" href="estilo.css">
|
||||
<title>Registro Pedidos</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h2>Registrar Pedido</h2>
|
||||
<form action="" method="post">
|
||||
<table>
|
||||
<tr>
|
||||
<th>Descripcion</th>
|
||||
<th>Precio</th>
|
||||
<th>Cantidad</th>
|
||||
</tr>
|
||||
<?php
|
||||
foreach ($productos as $producto) {
|
||||
echo "<tr>";
|
||||
echo "<td>$producto[nombre] </td> <td>$producto[precio] € </td>";
|
||||
echo "<td hidden> <input type='number' id='producto_id' name='producto_id[]' value=$producto[producto_id]></td>";
|
||||
echo "<td hidden> <input type='number' id='precio' name='precio[]' value=$producto[precio]></td>";
|
||||
echo "<td> <input type='number' id='cantidad' name='cantidad[]' value=0></td>";
|
||||
echo "</tr>";
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
<br>
|
||||
<input type="submit" value="Registrar Pedido">
|
||||
</form>
|
||||
</body>
|
||||
|
||||
<?php
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
|
||||
$lineas_pedido = array();
|
||||
$total_pedido = 0;
|
||||
|
||||
foreach (array_keys($_POST['producto_id']) as $index) {
|
||||
if ($_POST['cantidad'][$index] > 0) {
|
||||
$lineas_pedido[] = array(
|
||||
'producto_id' => intval($_POST['producto_id'][$index]),
|
||||
'cantidad' => intval($_POST['cantidad'][$index]),
|
||||
'precio' => floatval($_POST['precio'][$index]),
|
||||
'total_linea' => $_POST['cantidad'][$index] * $_POST['precio'][$index]
|
||||
);
|
||||
$total_pedido += $_POST['cantidad'][$index] * $_POST['precio'][$index];
|
||||
}
|
||||
}
|
||||
|
||||
$cliente_id = $_SESSION['cliente_id'];
|
||||
$nombre_servidor = "localhost";
|
||||
$nombre_usuario = "root";
|
||||
$contraseña = "Logomark8";
|
||||
$nombre_base_datos = "tienda";
|
||||
|
||||
mysqli_report(MYSQLI_REPORT_OFF);
|
||||
$conexion = mysqli_connect($nombre_servidor, $nombre_usuario, $contraseña, $nombre_base_datos);
|
||||
if (!$conexion) {
|
||||
exit("Error de conexión: " . mysqli_connect_error());
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
</html>
|
||||
|
|
@ -23,7 +23,7 @@
|
|||
<input type="text" id="username" name="username" required>
|
||||
|
||||
<label for="password">Contraseña:</label>
|
||||
<input type="text" id="password" name="password" required>
|
||||
<input type="password" id="password" name="password" required>
|
||||
|
||||
<input type="submit" value="Enviar">
|
||||
</form>
|
||||
|
|
@ -67,7 +67,7 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|||
echo "<p>El cliente ha sido registrado correctamente </p>";
|
||||
$mensaje = "Puedes loguearte, ya estás registrado";
|
||||
$mensaje_codificado = urlencode($mensaje);
|
||||
header("Location: login.php?mensaje=".$mensaje_codificado);
|
||||
header("Location: login.php?mensaje=" . $mensaje_codificado);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user