-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathform-ingreso-tester.php
More file actions
59 lines (48 loc) · 1.68 KB
/
form-ingreso-tester.php
File metadata and controls
59 lines (48 loc) · 1.68 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
// http://localhost:8080/dashboard/basedatos/form-ingreso-tester.php
// Incluir el archivo de conexión a la base de datos
include './config.php';
// Datos de conexión
$servidor = "localhost";
$baseDatos = "anima";
$usuario = "root";
$contrasena = "";
// Conectar a la base de datos
$conexion = conectar_bd($servidor, $baseDatos, $usuario, $contrasena);
// Verificar si el formulario ha sido enviado
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Obtener los datos del formulario
$nombre = $_POST["nombre"];
$correo = $_POST["correo"];
// Preparar la consulta INSERT
$sql = "INSERT INTO testers (nombre, correo) VALUES (:nombre, :correo)";
$consulta = $conexion->prepare($sql);
// Asignar valores a los parámetros de la consulta
$consulta->bindParam(":nombre", $nombre);
$consulta->bindParam(":correo", $correo);
// Ejecutar la consulta
if ($consulta->execute()) {
header("Location: exito.php?mensaje=Registro insertado correctamente.");
exit();
} else {
header("Location: error.php?mensaje=Error al insertar el registro.");
exit();
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Formulario de Registro</title>
</head>
<body>
<h1>Formulario de Registro</h1>
<form method="post" action="<?php echo $_SERVER["PHP_SELF"]; ?>">
<label for="nombre">Nombre:</label>
<input type="text" name="nombre" required>
<label for="correo">Correo:</label>
<input type="email" name="correo" required>
<input type="submit" value="Registrar">
</form>
</body>
</html>