Skip to content

Commit 0dbcf4a

Browse files
authored
Update user.php
1 parent 87622fc commit 0dbcf4a

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

user.php

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,70 @@
11
<!DOCTYPE html>
22
<html lang="en">
3-
43
<head>
54
<meta charset="UTF-8">
65
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7-
<title>Agregar Usuario | PHP CRUD</title>
6+
<title>Add User | PHP CRUD</title>
7+
<!-- Enlace al archivo CSS de Tailwind CSS para estilos -->
88
<link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet" />
99
</head>
10-
1110
<body>
1211
<div class="container mx-auto mt-12">
1312
<div class="flex justify-center items-center">
13+
<!-- Formulario para agregar usuarios -->
1414
<form action="user.php" method="POST" class="w-1/2">
1515
<div class="flex flex-col mb-4">
16-
<label for="name" class="mb-2 font-bold text-lg text-gray-900">Nombre</label>
17-
<input type="text" name="name" id="name" placeholder="Nombre"
16+
<label for="name" class="mb-2 font-bold text-lg text-gray-900">Name</label>
17+
<input type="text" name="name" id="name" placeholder="Name"
1818
class="border-2 border-gray-400 p-2 rounded-lg focus:outline-none focus:border-green-500" required>
1919
</div>
2020
<div class="flex flex-col mb-4">
21-
<label for="email" class="mb-2 font-bold text-lg text-gray-900">Correo Electrónico</label>
22-
<input type="email" name="email" id="email" placeholder="Correo Electrónico"
21+
<label for="email" class="mb-2 font-bold text-lg text-gray-900">Email</label>
22+
<input type="email" name="email" id="email" placeholder="Email"
2323
class="border-2 border-gray-400 p-2 rounded-lg focus:outline-none focus:border-green-500" required>
2424
</div>
2525
<div class="flex flex-col mb-4">
26-
<label for="mobile" class="mb-2 font-bold text-lg text-gray-900">Móvil</label>
27-
<input type="tel" name="mobile" id="mobile" placeholder="Móvil"
26+
<label for="mobile" class="mb-2 font-bold text-lg text-gray-900">Mobile</label>
27+
<input type="tel" name="mobile" id="mobile" placeholder="Mobile"
2828
class="border-2 border-gray-400 p-2 rounded-lg focus:outline-none focus:border-green-500" required>
2929
</div>
3030
<div class="flex flex-col mb-4">
31-
<label for="password" class="mb-2 font-bold text-lg text-gray-900">Contraseña</label>
32-
<input type="password" name="password" id="password" placeholder="Contraseña"
31+
<label for="password" class="mb-2 font-bold text-lg text-gray-900">Password</label>
32+
<input type="password" name="password" id="password" placeholder="Password"
3333
class="border-2 border-gray-400 p-2 rounded-lg focus:outline-none focus:border-green-500" required>
3434
</div>
3535
<div class="flex flex-col mb-4">
3636
<button type="submit" name="submit"
37-
class="bg-green-500 hover:bg-green-700 text-white font-bold py-2 rounded shadow-lg hover:shadow-xl transition duration-200">Enviar</button>
37+
class="bg-green-500 hover:bg-green-700 text-white font-bold py-2 rounded shadow-lg hover:shadow-xl transition duration-200">Submit</button>
3838
</div>
3939
</form>
4040
</div>
41+
</div>
4142
</body>
42-
4343
</html>
4444

4545
<?php
46+
// Se incluye el archivo de conexión a la base de datos
4647
include 'connect.php';
48+
// Se verifica si se ha enviado el formulario
4749
if (isset($_POST['submit'])) {
50+
// Se obtienen los datos del formulario
4851
$name = $_POST['name'];
4952
$email = $_POST['email'];
5053
$mobile = $_POST['mobile'];
5154
$password = $_POST['password'];
5255

56+
// Se crea la consulta SQL para insertar los datos en la base de datos
5357
$sql = "INSERT INTO crud (name, email, mobile, password) VALUES ('$name', '$email', '$mobile', '$password')";
58+
59+
// Se ejecuta la consulta SQL y se verifica si fue exitosa
5460
if (mysqli_query($conn, $sql)) {
55-
echo "<script>alert('Usuario agregado exitosamente.')</script>";
61+
echo "<script>alert('User added successfully.')</script>";
5662
} else {
63+
// En caso de error, se muestra un mensaje de error
5764
echo "<script>console.log('Error: " . $sql . "<br>" . mysqli_error($conn) . "')</script>";
5865
}
66+
67+
// Se cierra la conexión a la base de datos
5968
mysqli_close($conn);
6069
}
6170
?>

0 commit comments

Comments
 (0)