-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroladorBorrarVotantes.php
48 lines (38 loc) · 1.23 KB
/
controladorBorrarVotantes.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
39
40
41
42
43
44
45
46
47
48
<?php
session_start();
include 'conexionBD.php';
if (isset($_SESSION['user']))
$dni = $_SESSION['user'];
if (isset($_REQUEST["dni"]))
$dni = $_REQUEST["dni"];
$sql = "SELECT apellidos,nombre FROM votante WHERE nif='" . $dni . "'";
$memory = $conexion->query($sql);
if ($memory && $memory->num_rows > 0) {
$info = $memory->fetch_array();
$sql = "SELECT * FROM convocatoria WHERE escrutinio='Abierto'";
$memory = $conexion->query($sql);
if ($memory && $memory->num_rows > 0) {
$_SESSION['mensajeBD'] = "No puedes borrar tu usuario mientras este el escrutinio abierto";
header("Location:MensajeErrores.php");
exit;
}
}
// Prevent SQL Injection
$sql1 = "DELETE FROM votante WHERE nif=? AND votante='No'";
$check = $conexion->prepare($sql1);
$check->bind_param("s", $Vdni);
$Vdni = $dni;
$check->execute();
if ($conexion->affected_rows > 0) {
$_SESSION['mensajeBD'] = "Se ha borrado a " . $info['nombre'] . " " . $info['apellidos'] . " de la base de datos.";
if ($_SESSION['user'] == $dni) {
unset($_SESSION['user']);
unset($_SESSION['rol']);
}
header("Location:MensajeErrores.php");
} else {
$_SESSION['mensajeBD'] = "Este votante no existe o ya has votado.";
header("Location:MensajeErrores.php");
exit;
}
?>