|
1 | 1 | <!DOCTYPE html>
|
2 | 2 | <html lang="en">
|
3 |
| - |
4 | 3 | <head>
|
5 | 4 | <meta charset="UTF-8">
|
6 | 5 | <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 --> |
8 | 8 | <link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet" />
|
9 | 9 | </head>
|
10 |
| - |
11 | 10 | <body>
|
12 | 11 | <div class="container mx-auto mt-12">
|
13 | 12 | <div class="flex justify-center items-center">
|
| 13 | + <!-- Formulario para agregar usuarios --> |
14 | 14 | <form action="user.php" method="POST" class="w-1/2">
|
15 | 15 | <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" |
18 | 18 | class="border-2 border-gray-400 p-2 rounded-lg focus:outline-none focus:border-green-500" required>
|
19 | 19 | </div>
|
20 | 20 | <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" |
23 | 23 | class="border-2 border-gray-400 p-2 rounded-lg focus:outline-none focus:border-green-500" required>
|
24 | 24 | </div>
|
25 | 25 | <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" |
28 | 28 | class="border-2 border-gray-400 p-2 rounded-lg focus:outline-none focus:border-green-500" required>
|
29 | 29 | </div>
|
30 | 30 | <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" |
33 | 33 | class="border-2 border-gray-400 p-2 rounded-lg focus:outline-none focus:border-green-500" required>
|
34 | 34 | </div>
|
35 | 35 | <div class="flex flex-col mb-4">
|
36 | 36 | <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> |
38 | 38 | </div>
|
39 | 39 | </form>
|
40 | 40 | </div>
|
| 41 | + </div> |
41 | 42 | </body>
|
42 |
| - |
43 | 43 | </html>
|
44 | 44 |
|
45 | 45 | <?php
|
| 46 | +// Se incluye el archivo de conexión a la base de datos |
46 | 47 | include 'connect.php';
|
| 48 | +// Se verifica si se ha enviado el formulario |
47 | 49 | if (isset($_POST['submit'])) {
|
| 50 | + // Se obtienen los datos del formulario |
48 | 51 | $name = $_POST['name'];
|
49 | 52 | $email = $_POST['email'];
|
50 | 53 | $mobile = $_POST['mobile'];
|
51 | 54 | $password = $_POST['password'];
|
52 | 55 |
|
| 56 | + // Se crea la consulta SQL para insertar los datos en la base de datos |
53 | 57 | $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 |
54 | 60 | if (mysqli_query($conn, $sql)) {
|
55 |
| - echo "<script>alert('Usuario agregado exitosamente.')</script>"; |
| 61 | + echo "<script>alert('User added successfully.')</script>"; |
56 | 62 | } else {
|
| 63 | + // En caso de error, se muestra un mensaje de error |
57 | 64 | echo "<script>console.log('Error: " . $sql . "<br>" . mysqli_error($conn) . "')</script>";
|
58 | 65 | }
|
| 66 | + |
| 67 | + // Se cierra la conexión a la base de datos |
59 | 68 | mysqli_close($conn);
|
60 | 69 | }
|
61 | 70 | ?>
|
0 commit comments