Skip to content

Instantly share code, notes, and snippets.

@guibranco
Last active October 17, 2017 18:56
Show Gist options
  • Save guibranco/b9a13b29fa6592c7971c366e1c6dfa32 to your computer and use it in GitHub Desktop.
Save guibranco/b9a13b29fa6592c7971c366e1c6dfa32 to your computer and use it in GitHub Desktop.
<?php
session_start();
$btn_votar = filter_input(INPUT_POST,'votar', FILTER_SANITIZE_STRING);
if(!$btn_votar)
header('location:../votacao.php');
$categoria= $_POST['categoria'];
$nome=$_POST['voto1'];
$ip=$_SERVER['REMOTE_ADDR'];
require_once('../conexao.php');
if(!empty($categoria) and !empty($nome) and !empty($ip)){
$grava = mysqli_query($conexao, "INSERT INTO votantes (ip, cat, nome, data) VALUES('$ip','$categoria','$nome',NOW())") or die(mysqli_error()); //para ver se gera erro
if(mysqli_insert_id($conexao)){
$vota = mysqli_query($conexao,"UPDATE $categoria SET votos = votos + 1 WHERE nome = '$nome'") or die(mysqli_error()); //para ver se gera erro
if(mysqli_affected_rows($conexao) > 0)
$_SESSION['alert']="Votaste com sucesso em ".$nome. " <i class='fa fa-check' aria-hidden='true'></i>";
else
$_SESSION['alert']="Não foi possivel votar em ".$nome;
}else
$_SESSION['alert']="Não foi possivel votar em ".$nome;
}else
$_SESSION['alert']="Não foi possivel votar em ".$nome;
mysqli_close($conexao);
header("location:../votacao.php?cat=$categoria#$categoria");
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment