-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvoto.php
More file actions
51 lines (41 loc) · 1.36 KB
/
voto.php
File metadata and controls
51 lines (41 loc) · 1.36 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
SALVANDO VOTO...
<?php
include('rest.php');
include('conectar.php');
$id_cand = $_POST['voto'];
// Assuming $login_user is set somewhere before
$query_guy = $conexao->prepare("SELECT id_user FROM user WHERE nickname_user = ?");
$query_guy->bind_param("s", $login_user);
$query_guy->execute();
$query_guy->bind_result($id_user);
$query_guy->fetch();
$query_guy->close();
$query_votos = $conexao->prepare("SELECT COUNT(*) FROM votos WHERE iduser_voto = ?");
$query_votos->bind_param("i", $id_user);
$query_votos->execute();
$query_votos->bind_result($nvoto);
$query_votos->fetch();
$query_votos->close();
if ($nvoto == 0) {
$query_cand = $conexao->prepare("SELECT votos_capreg FROM capone_reg WHERE idcand_capreg = ?");
$query_cand->bind_param("i", $id_cand);
$query_cand->execute();
$query_cand->bind_result($vottot);
$query_cand->fetch();
$query_cand->close();
$vottot_new = $vottot + 1;
$query1 = $conexao->prepare("INSERT INTO votos(iduser_voto) VALUES (?)");
$query1->bind_param("i", $id_user);
$query1->execute();
$query1->close();
$query2 = $conexao->prepare("UPDATE capone_reg SET votos_capreg = ? WHERE idcand_capreg = ?");
$query2->bind_param("ii", $vottot_new, $id_cand);
$query2->execute();
$query2->close();
header("Location: capo.php");
exit;
} else {
header("Location: capo.php");
exit;
}
?>