-
Notifications
You must be signed in to change notification settings - Fork 0
/
guardar.php
38 lines (33 loc) · 935 Bytes
/
guardar.php
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
<?php
include 'conexion.php';
// Obtener los valores del formulario
$rut = $_POST["rut"];
$nombre = $_POST['nombre'];
$alias = $_POST["alias"];
$correo = $_POST['email'];
$region = $_POST['region'];
$comuna = $_POST['comuna'];
$candidato = $_POST['candidato'];
$recomendaciones = implode(',', $_POST['recomendaciones']);
$sql = "SELECT * FROM votante WHERE rut = '$rut' AND alias = '$alias'";
$result = pg_query($conexion, $sql);
if (pg_num_rows($result) > 0) {
$response = array(
'status' => 'error',
'message' => 'Ya existe un registro con ese rut y/o alias.'
);
} else {
$query = pg_query($conexion, $sql);
if ($query) {
$response = array(
'status' => 'success',
'message' => 'Datos guardados correctamente.'
);
} else {
$response = array(
'status' => 'error',
'message' => 'Error al guardar los datos: ' . pg_last_error($conexion)
);
}
}
echo json_encode($response);