CRUD
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
function connection(){
|
||||
$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());
|
||||
}
|
||||
return $conexion;
|
||||
}
|
||||
?>
|
||||
156
Practicas/Practicas_SQL/ejercicios/tienda/crud/css/style.css
Normal file
156
Practicas/Practicas_SQL/ejercicios/tienda/crud/css/style.css
Normal file
@@ -0,0 +1,156 @@
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
html {
|
||||
font-family: 'Segoe UI', sans-serif;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
a{
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.users-form form{
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
width: 30%;
|
||||
margin: 10px auto;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.users-form form input{
|
||||
font-family: 'Segoe UI', sans-serif;
|
||||
}
|
||||
|
||||
.users-form form input[type=text],
|
||||
.users-form form input[type=password],
|
||||
.users-form form input[type=email]{
|
||||
padding: 8px;
|
||||
border:2px solid #aaa;
|
||||
border-radius:4px;
|
||||
outline:none;
|
||||
transition:.3s;
|
||||
}
|
||||
|
||||
.users-form form input[type=text]:focus,
|
||||
.users-form form input[type=password]:focus,
|
||||
.users-form form input[type=password]:focus{
|
||||
border-color:dodgerBlue;
|
||||
box-shadow:0 0 6px 0 dodgerBlue;
|
||||
}
|
||||
|
||||
.users-form form input[type=submit]{
|
||||
border: none;
|
||||
padding: 12px 50px;
|
||||
text-decoration: none;
|
||||
transition-duration: 0.4s;
|
||||
cursor: pointer;
|
||||
border-radius: 5px;
|
||||
background-color: white;
|
||||
color: black;
|
||||
border: 2px solid #60a100;
|
||||
}
|
||||
|
||||
.users-form form input[type=submit]:hover {
|
||||
background-color: #60a100;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.users-table table{
|
||||
border: 1px solid #ccc;
|
||||
border-collapse: collapse;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
width: 100%;
|
||||
table-layout: fixed;
|
||||
}
|
||||
|
||||
.detail-table table{
|
||||
border: 1px solid #ccc;
|
||||
border-collapse: collapse;
|
||||
margin: auto;
|
||||
padding: 0;
|
||||
width: 60%;
|
||||
table-layout: fixed;
|
||||
}
|
||||
|
||||
table tr {
|
||||
background-color: #f8f8f8;
|
||||
border: 1px solid #ddd;
|
||||
padding: 4px;
|
||||
}
|
||||
|
||||
table th{
|
||||
padding: 10px;
|
||||
text-align: center;
|
||||
font-size: .85em;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
max-width: 200px;
|
||||
}
|
||||
|
||||
|
||||
.users-table--detail{
|
||||
background: #09adc8;
|
||||
padding: 6px;
|
||||
color: #fff;
|
||||
text-align: center;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.users-table--edit{
|
||||
background: #009688;
|
||||
padding: 6px;
|
||||
color: #fff;
|
||||
text-align: center;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.users-table--delete{
|
||||
background: #b11e1e;
|
||||
padding: 6px;
|
||||
color: #fff;
|
||||
text-align: center;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
/* Estilos básicos para el menú */
|
||||
nav {
|
||||
background-color: #333;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
nav ul {
|
||||
list-style-type: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
nav li {
|
||||
display: inline;
|
||||
margin-right: 20px;
|
||||
}
|
||||
|
||||
nav a {
|
||||
text-decoration: none;
|
||||
color: #fff;
|
||||
font-size: 18px;
|
||||
padding: 10px 20px;
|
||||
border-radius: 5px;
|
||||
transition: background-color 0.3s ease;
|
||||
}
|
||||
|
||||
nav a:hover {
|
||||
background-color: #555;
|
||||
}
|
||||
|
||||
/* Estilos para los enlaces activos */
|
||||
nav .active a {
|
||||
background-color: #007bff;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
include("connection.php");
|
||||
$con = connection();
|
||||
|
||||
$pedido_id = $_GET["pedido_id"];
|
||||
|
||||
|
||||
// Borrar en productos
|
||||
$sql = "DELETE FROM pedidos WHERE pedido_id='$pedido_id'";
|
||||
$query = mysqli_query($con, $sql);
|
||||
|
||||
if ($query) {
|
||||
Header("Location: index_pedidos.php");
|
||||
} else {
|
||||
$mensaje = "Se ha producido un error al borrar el registro.";
|
||||
$mensaje_codificado = urlencode($mensaje);
|
||||
header("Location: index_pedidos.php?mensaje=" . $mensaje_codificado);
|
||||
exit;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
include("connection.php");
|
||||
$con = connection();
|
||||
|
||||
$producto_id = $_GET["producto_id"];
|
||||
|
||||
|
||||
// Borrar en productos
|
||||
$sql = "DELETE FROM productos WHERE producto_id='$producto_id'";
|
||||
$query = mysqli_query($con, $sql);
|
||||
|
||||
if ($query) {
|
||||
Header("Location: index_productos.php");
|
||||
} else {
|
||||
$mensaje = "Se ha producido un error al borrar el registro.";
|
||||
$mensaje_codificado = urlencode($mensaje);
|
||||
header("Location: index_productos.php?mensaje=" . $mensaje_codificado);
|
||||
exit;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
include("connection.php");
|
||||
$con = connection();
|
||||
|
||||
$cliente_id=$_GET["cliente_id"];
|
||||
|
||||
// Borrar en usuarios
|
||||
// $sql_usuarios="DELETE FROM usuarios WHERE cliente_id='$cliente_id'";
|
||||
// $query_usuarios = mysqli_query($con, $sql_usuarios);
|
||||
|
||||
// Borrar en clientes
|
||||
$sql="DELETE FROM clientes WHERE cliente_id='$cliente_id'";
|
||||
$query = mysqli_query($con, $sql);
|
||||
|
||||
|
||||
//if($query AND $query_usuarios){
|
||||
if($query){
|
||||
Header("Location: index_clientes.php");
|
||||
}else{
|
||||
$mensaje ="Se ha producido un error al borrar el registro.";
|
||||
$mensaje_codificado = urlencode($mensaje);
|
||||
header("Location: index_clientes.php?mensaje=".$mensaje_codificado);
|
||||
exit;
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
include("connection.php");
|
||||
$con = connection();
|
||||
|
||||
// Recuperar los datos del formulario
|
||||
$producto_id = $_POST["producto_id"];
|
||||
$nombre = $_POST["nombre"];
|
||||
$precio = $_POST["precio"];
|
||||
|
||||
|
||||
// Actualizo en productos
|
||||
$sql = "UPDATE productos SET nombre='$nombre', precio='$precio' WHERE producto_id='$producto_id'";
|
||||
$query = mysqli_query($con, $sql);
|
||||
|
||||
|
||||
if($query){
|
||||
$mensaje ="Producto actualizado.";
|
||||
$mensaje_codificado = urlencode($mensaje);
|
||||
header("Location: index_productos.php?mensaje=".$mensaje_codificado);
|
||||
exit;
|
||||
}else{
|
||||
$mensaje ="Se ha producido un error al actualizar.";
|
||||
$mensaje_codificado = urlencode($mensaje);
|
||||
header("Location: index_productos.php?mensaje=".$mensaje_codificado);
|
||||
exit;
|
||||
}
|
||||
34
Practicas/Practicas_SQL/ejercicios/tienda/crud/edit_user.php
Normal file
34
Practicas/Practicas_SQL/ejercicios/tienda/crud/edit_user.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
include("connection.php");
|
||||
$con = connection();
|
||||
|
||||
// Recuperar los datos del formulario
|
||||
$cliente_id = $_POST["cliente_id"];
|
||||
$nombre = $_POST["nombre"];
|
||||
$correo = $_POST["correo"];
|
||||
$direccion = $_POST["direccion"];
|
||||
$nombre_usuario = $_POST["nombre_usuario"];
|
||||
$contrasena = $_POST["contrasena"];
|
||||
|
||||
// Actualizo en clientes
|
||||
$sql = "UPDATE clientes SET nombre='$nombre', correo_electronico='$correo', direccion='$direccion' WHERE cliente_id='$cliente_id'";
|
||||
$query = mysqli_query($con, $sql);
|
||||
|
||||
|
||||
// Actualizo en usuarios
|
||||
$sql_usuarios = "UPDATE usuarios SET nombre_usuario='$nombre_usuario', contraseña='$contrasena' WHERE cliente_id='$cliente_id'";
|
||||
$query_usuarios = mysqli_query($con, $sql_usuarios);
|
||||
|
||||
|
||||
if($query AND $query_usuarios){
|
||||
$mensaje ="Usuario actualizado.";
|
||||
$mensaje_codificado = urlencode($mensaje);
|
||||
header("Location: index_clientes.php?mensaje=".$mensaje_codificado);
|
||||
exit;
|
||||
}else{
|
||||
$mensaje ="Se ha producido un error al actualizar.";
|
||||
$mensaje_codificado = urlencode($mensaje);
|
||||
header("Location: index_clientes.php?mensaje=".$mensaje_codificado);
|
||||
exit;
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 65 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 117 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 283 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 320 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 131 KiB |
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
include("connection.php");
|
||||
$con = connection();
|
||||
|
||||
$sql = "SELECT * FROM clientes_usuarios";
|
||||
$query = mysqli_query($con, $sql);
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="es">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link href="css/style.css" rel="stylesheet">
|
||||
<title>Clientes CRUD</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<nav>
|
||||
<ul>
|
||||
<li class="active"><a href="index_clientes.php">Clientes</a></li>
|
||||
<li><a href="index_productos.php">Productos</a></li>
|
||||
<li><a href="index_pedidos.php">Pedidos</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
<div class="users-table">
|
||||
<h2>Registro de Clientes</h2>
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<form action="insert_user.php" method="POST">
|
||||
<label for="nombre">Nombre:</label>
|
||||
</td>
|
||||
<td>
|
||||
<label for="correo">Correo electrónico:</label>
|
||||
</td>
|
||||
<td>
|
||||
<label for="direccion">Dirección:</label>
|
||||
</td>
|
||||
<td>
|
||||
<label for="nombre_usuario">Nombre de usuario:</label>
|
||||
</td>
|
||||
<td>
|
||||
<label for="contrasena">Contraseña:</label>
|
||||
</td>
|
||||
<td>
|
||||
</td> <!-- Celda vacía para el botón de envío -->
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<input type="text" name="nombre" id="nombre" required>
|
||||
</td>
|
||||
<td>
|
||||
<input type="email" name="correo" id="correo" required>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" name="direccion" id="direccion" required>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" name="nombre_usuario" id="nombre_usuario" required>
|
||||
</td>
|
||||
<td>
|
||||
<input type="password" name="contrasena" id="contrasena" required>
|
||||
</td>
|
||||
<td>
|
||||
<input type="submit" value="Registrarse">
|
||||
</td>
|
||||
</form>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
||||
<?php if (isset($_GET['mensaje'])) echo "<p>" . $_GET['mensaje'] . "</p>"; ?>
|
||||
</div>
|
||||
|
||||
<div class="users-table">
|
||||
<h2>Clientes registrados</h2>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Cliente ID</th>
|
||||
<th>Nombre</th>
|
||||
<th>Correo Electrónico</th>
|
||||
<th>Dirección</th>
|
||||
<th>Nombre usuario</th>
|
||||
<th>Password</th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php while ($fila = mysqli_fetch_array($query)) { ?>
|
||||
<tr>
|
||||
<th><?php echo $fila['cliente_id'] ?></th>
|
||||
<th><?php echo $fila['nombre'] ?></th>
|
||||
<th><?php echo $fila['correo_electronico'] ?></th>
|
||||
<th><?php echo $fila['direccion'] ?></th>
|
||||
<th><?php echo $fila['nombre_usuario'] ?></th>
|
||||
<th><?php echo $fila['contraseña'] ?></th>
|
||||
<th><a href="update_user.php?cliente_id=<?php echo $fila['cliente_id'] ?>" class="users-table--edit">Editar</a></th>
|
||||
<th><a href="delete_user.php?cliente_id=<?php echo $fila['cliente_id'] ?>" class="users-table--delete">Eliminar</a></th>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
104
Practicas/Practicas_SQL/ejercicios/tienda/crud/index_pedidos.php
Normal file
104
Practicas/Practicas_SQL/ejercicios/tienda/crud/index_pedidos.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
include("connection.php");
|
||||
$con = connection();
|
||||
|
||||
$sql = "SELECT * FROM pedidos";
|
||||
$query = mysqli_query($con, $sql);
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="es">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link href="css/style.css" rel="stylesheet">
|
||||
<title>Predidos CRUD</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<nav>
|
||||
<ul>
|
||||
<li><a href="index_clientes.php">Clientes</a></li>
|
||||
<li><a href="index_productos.php">Productos</a></li>
|
||||
<li class="active"><a href="index_pedidos.php">Pedidos</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
<!-- <div class="users-table">
|
||||
<h2>Registro de Productos</h2>
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<form action="insert_producto.php" method="POST">
|
||||
<label for="nombre">Nombre:</label>
|
||||
</td>
|
||||
<td>
|
||||
<label for="correo">Precio:</label>
|
||||
</td>
|
||||
<td>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<input type="text" name="nombre" id="nombre" required>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" name="precio" id="precio" required>
|
||||
</td>
|
||||
<td>
|
||||
<td>
|
||||
<input type="submit" value="Registrarse">
|
||||
</td>
|
||||
</form>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
||||
<?php if (isset($_GET['mensaje'])) echo "<p>" . $_GET['mensaje'] . "</p>"; ?>
|
||||
</div> -->
|
||||
|
||||
<div class="users-table">
|
||||
<h2>Pedidos registrados</h2>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Pedido ID</th>
|
||||
<th>Cliente ID</th>
|
||||
<th>Fecha</th>
|
||||
<th>Estado</th>
|
||||
<th>Total</th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php while ($fila = mysqli_fetch_array($query)) { ?>
|
||||
<tr>
|
||||
<th><?php echo $fila['pedido_id'] ?></th>
|
||||
<th><?php echo $fila['cliente_id'] ?></th>
|
||||
<th><?php echo $fila['fecha'] ?></th>
|
||||
<th> <select id="estado_pedido" onchange="cambiarEstado(<?php echo $fila['pedido_id'] ?>,this.value)">
|
||||
<option <?php echo $fila['estado'] === 'pendiente' ? 'selected' : ''; ?> value="pendiente">Pendiente</option>
|
||||
<option <?php echo $fila['estado'] === 'en_preparacion' ? 'selected' : ''; ?> value="en_preparacion">En preparacion</option>
|
||||
<option <?php echo $fila['estado'] === 'enviado' ? 'selected' : ''; ?> value="enviado">Enviado</option>
|
||||
<option <?php echo $fila['estado'] === 'completado' ? 'selected' : ''; ?> value="completado">Completado</option>
|
||||
</select></th>
|
||||
|
||||
<th><?php echo $fila['total'] ?></th>
|
||||
<th><a href="update_producto.php?producto_id=<?php echo $fila['pedido_id'] ?>" class="users-table--edit">Ver Detalle</a></th>
|
||||
<th><a href="delete_pedido.php?pedido_id=<?php echo $fila['pedido_id'] ?>" class="users-table--delete">Eliminar</a></th>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<script>
|
||||
function cambiarEstado(pedido_id, estado) {
|
||||
window.location.href = "update_estado_pedido.php?pedido_id=" + pedido_id + "&estado=" + estado;
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
include("connection.php");
|
||||
$con = connection();
|
||||
|
||||
$sql = "SELECT * FROM productos";
|
||||
$query = mysqli_query($con, $sql);
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="es">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link href="css/style.css" rel="stylesheet">
|
||||
<title>Productos CRUD</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<nav>
|
||||
<ul>
|
||||
<li><a href="index_clientes.php">Clientes</a></li>
|
||||
<li class="active"><a href="index_productos.php">Productos</a></li>
|
||||
<li><a href="index_pedidos.php">Pedidos</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
<div class="users-table">
|
||||
<h2>Registro de Productos</h2>
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<form action="insert_producto.php" method="POST">
|
||||
<label for="nombre">Nombre:</label>
|
||||
</td>
|
||||
<td>
|
||||
<label for="correo">Precio:</label>
|
||||
</td>
|
||||
<td>
|
||||
</td> <!-- Celda vacía para el botón de envío -->
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<input type="text" name="nombre" id="nombre" required>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" name="precio" id="precio" required>
|
||||
</td>
|
||||
<td>
|
||||
<td>
|
||||
<input type="submit" value="Registrarse">
|
||||
</td>
|
||||
</form>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
||||
<?php if (isset($_GET['mensaje'])) echo "<p>" . $_GET['mensaje'] . "</p>"; ?>
|
||||
</div>
|
||||
|
||||
<div class="users-table">
|
||||
<h2>Productos registrados</h2>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Producto ID</th>
|
||||
<th>Nombre</th>
|
||||
<th>Precio</th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php while ($fila = mysqli_fetch_array($query)) { ?>
|
||||
<tr>
|
||||
<th><?php echo $fila['producto_id'] ?></th>
|
||||
<th><?php echo $fila['nombre'] ?></th>
|
||||
<th><?php echo $fila['precio'] ?></th>
|
||||
<th><a href="update_producto.php?producto_id=<?php echo $fila['producto_id'] ?>" class="users-table--edit">Editar</a></th>
|
||||
<th><a href="delete_producto.php?producto_id=<?php echo $fila['producto_id'] ?>" class="users-table--delete">Eliminar</a></th>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
include("connection.php");
|
||||
$con = connection();
|
||||
|
||||
// Verificar si se ha enviado el formulario
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
|
||||
// Recuperar los datos del formulario
|
||||
$nombre = $_POST["nombre"];
|
||||
$precio = $_POST["precio"];
|
||||
|
||||
|
||||
// Desactivar los informes de errores de MySQLi
|
||||
mysqli_report(MYSQLI_REPORT_OFF);
|
||||
|
||||
|
||||
$insercion_sql = "INSERT INTO productos (nombre, precio) VALUES ('$nombre', '$precio')";
|
||||
|
||||
$resultado = mysqli_query($con, $insercion_sql);
|
||||
if (!$resultado) {
|
||||
$mensaje = "Error al crear al producto.";
|
||||
$mensaje_codificado = urlencode($mensaje);
|
||||
header("Location: index_productos.php?mensaje=" . $mensaje_codificado);
|
||||
exit();
|
||||
} else {
|
||||
$mensaje = "Producto creado correctamente.";
|
||||
$mensaje_codificado = urlencode($mensaje);
|
||||
header("Location: index_productos.php?mensaje=" . $mensaje_codificado);
|
||||
exit();
|
||||
}
|
||||
// Liberar el resultado
|
||||
mysqli_free_result($resultado);
|
||||
// Cerrar la conexión
|
||||
mysqli_close($con);
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
include("connection.php");
|
||||
$con = connection();
|
||||
|
||||
// Verificar si se ha enviado el formulario
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
|
||||
// Recuperar los datos del formulario
|
||||
$nombre = $_POST["nombre"];
|
||||
$correo = $_POST["correo"];
|
||||
$direccion = $_POST["direccion"];
|
||||
$nombre_usuario = $_POST["nombre_usuario"];
|
||||
$contrasena = $_POST["contrasena"];
|
||||
|
||||
// Desactivar los informes de errores de MySQLi
|
||||
mysqli_report(MYSQLI_REPORT_OFF);
|
||||
|
||||
// Verificar si el correo electrónico ya está en la base de datos
|
||||
$consulta_correo = "SELECT * FROM clientes WHERE correo_electronico = '$correo'";
|
||||
$resultado_correo = mysqli_query($con, $consulta_correo);
|
||||
|
||||
if (mysqli_num_rows($resultado_correo) > 0 ) {
|
||||
$mensaje ="El correo electrónico ya está registrado.";
|
||||
$mensaje_codificado = urlencode($mensaje);
|
||||
header("Location: index_clientes.php?mensaje=".$mensaje_codificado);
|
||||
exit;
|
||||
} else {
|
||||
// Insertar el nuevo cliente en la tabla Clientes
|
||||
$insercion_cliente = "INSERT INTO clientes (nombre, correo_electronico, direccion) VALUES ('$nombre', '$correo', '$direccion')";
|
||||
if (mysqli_query($con, $insercion_cliente)) {
|
||||
// Insertar el nuevo usuario en la tabla Usuarios
|
||||
$hash_contrasena = password_hash($contrasena, PASSWORD_DEFAULT); // Encriptar la contraseña
|
||||
$insercion_usuario = "INSERT INTO usuarios (nombre_usuario, contraseña, cliente_id, correo_electronico)
|
||||
SELECT '$nombre_usuario', '$hash_contrasena', cliente_id, '$correo'
|
||||
FROM clientes WHERE correo_electronico = '$correo'";
|
||||
|
||||
|
||||
if (mysqli_query($con, $insercion_usuario)) {
|
||||
|
||||
// Redirigir al usuario a la página de realizar pedidos
|
||||
$mensaje = "El usuario ha sido registrado";
|
||||
$mensaje_codificado = urlencode($mensaje);
|
||||
header("Location: index_clientes.php?mensaje=".$mensaje_codificado);
|
||||
exit;
|
||||
} else {
|
||||
$mensaje ="Error al inscribir al usuario.";
|
||||
$mensaje_codificado = urlencode($mensaje);
|
||||
header("Location: index_clientes.php?mensaje=".$mensaje_codificado);
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
|
||||
$mensaje ="Error al inscribir al cliente.";
|
||||
$mensaje_codificado = urlencode($mensaje);
|
||||
header("Location: index_clientes.php?mensaje=".$mensaje_codificado);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
// Liberar el resultado
|
||||
mysqli_free_result($resultado_correo);
|
||||
// Cerrar la conexión
|
||||
mysqli_close($con);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
include("connection.php");
|
||||
$con = connection();
|
||||
|
||||
$pedido_id = $_GET['pedido_id'];
|
||||
$estado = $_GET['estado'];
|
||||
|
||||
$sql = "UPDATE pedidos SET estado='$estado' WHERE pedido_id='$pedido_id'";
|
||||
$query = mysqli_query($con, $sql);
|
||||
|
||||
if($query){
|
||||
$mensaje ="Pedido actualizado.";
|
||||
$mensaje_codificado = urlencode($mensaje);
|
||||
header("Location: index_pedidos.php?mensaje=".$mensaje_codificado);
|
||||
exit;
|
||||
}else{
|
||||
$mensaje ="Se ha producido un error al actualizar.";
|
||||
$mensaje_codificado = urlencode($mensaje);
|
||||
header("Location: index_pedidos.php?mensaje=".$mensaje_codificado);
|
||||
exit;
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
include("connection.php");
|
||||
$con = connection();
|
||||
|
||||
$producto_id = $_GET['producto_id'];
|
||||
|
||||
$sql = "SELECT * FROM productos
|
||||
WHERE producto_id = '$producto_id'";
|
||||
|
||||
$query = mysqli_query($con, $sql);
|
||||
$fila = mysqli_fetch_array($query);
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link href="css/style.css" rel="stylesheet">
|
||||
<title>Editar producto</title>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="users-form">
|
||||
<form action="edit_producto.php" method="POST">
|
||||
<input type="hidden" name="producto_id" id="producto_id" value="<?= $fila['producto_id'] ?>" />
|
||||
<label for="nombre">Nombre:</label>
|
||||
<input type="text" name="nombre" id="nombre" value="<?= $fila['nombre'] ?>" required>
|
||||
<br><br>
|
||||
<label for="precio">Precio:</label>
|
||||
<input type="text" name="precio" id="precio" value="<?= $fila['precio'] ?>" required>
|
||||
<br><br>
|
||||
<input type="submit" value="Actualizar">
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
include("connection.php");
|
||||
$con = connection();
|
||||
|
||||
$cliente_id = $_GET['cliente_id'];
|
||||
|
||||
$sql = "SELECT * FROM clientes_usuarios
|
||||
WHERE cliente_id = '$cliente_id'";
|
||||
|
||||
$query = mysqli_query($con, $sql);
|
||||
$fila = mysqli_fetch_array($query);
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link href="css/style.css" rel="stylesheet">
|
||||
<title>Editar usuarios</title>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="users-form">
|
||||
<form action="edit_user.php" method="POST">
|
||||
<input type="hidden" name="cliente_id" id="cliente_id" value="<?= $fila['cliente_id'] ?>" />
|
||||
<label for="nombre">Nombre:</label>
|
||||
<input type="text" name="nombre" id="nombre" value="<?= $fila['nombre'] ?>" required>
|
||||
<br><br>
|
||||
<label for="correo">Correo electrónico:</label>
|
||||
<input type="email" name="correo" id="correo" value="<?= $fila['correo_electronico'] ?>" required>
|
||||
<br><br>
|
||||
<label for="direccion">Dirección:</label>
|
||||
<input type="text" name="direccion" id="direccion" value="<?= $fila['direccion'] ?>" required>
|
||||
<br><br>
|
||||
<label for="nombre_usuario">Nombre de usuario:</label>
|
||||
<input type="text" name="nombre_usuario" id="nombre_usuario" value="<?= $fila['nombre_usuario'] ?>" required>
|
||||
<br><br>
|
||||
<label for="contrasena">Contraseña:</label>
|
||||
<input type="password" name="contrasena" id="contrasena" value="<?= $fila['contraseña'] ?>" required>
|
||||
<br><br>
|
||||
|
||||
<input type="submit" value="Actualizar">
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user