Limit sending the same email in the form?

0

I have this form

<form method="POST" action="/bolao/home/selecoes/russia/cadastrar.php">
<label>
<label>
<div align="center">Nome</div>
</label>
<div align="center">
  <input type="text" name="nome" id="nome">
  <br>
</div>
<label>
<div align="center">Email</div>
</label>
<div align="center">
  <input type="text" name="email" id="email">
  <br>
</div>
<div align="center"><br>
</div>
  <div align="center">
  <div align="center"><br />
    <strong>Palpites Grupo A <span class="style1">PRIMEIRA</span> Rodada dias 14/06 e 15/06</strong><br />
    <textarea name="palpites" id="palpites" cols="45" rows="2">RUSSIA X - X ARABIA SAUDITA
EGITO X - X URUGUAI
      </textarea>
    <br />
    <br />
    <strong>Palpites Grupo A <span class="style1">SEGUNDA</span> Rodada dias 19/06 e 20/06</strong><br />
    <textarea name="palpites2" id="palpites2" cols="45" rows="2">RUSSIA X - X EGITO
URUGUAI X - X ARABIA SAUDITA
      </textarea>
    <br />
    <br />
    <strong>Palpites Grupo A <span class="style1">TERCEIRA</span> Rodada dia 25/06</strong><br />
      <textarea name="palpites3" id="palpites3" cols="45" rows="2">RUSSIA X - X EGITO
ARABI SAUDITA X - X EGITO
      </textarea>
    <br />
    <br />
    </p>
    <input type="submit" value="Cadastrar Palpites" id="cadastrar" name="cadastrar" />
  </div>
  </form>

And my cadastrar.php     

$nome = $_POST['nome'];
$email = $_POST['email'];
$palpites = $_POST['palpites'];
$palpites2 = $_POST['palpites2'];
$palpites3 = $_POST['palpites3'];
$connect = mysql_connect('localhost','root','');
$db = mysql_select_db('copa');
$query_select = "SELECT nome FROM palpites WHERE nome = '$nome'";
$select = mysql_query($query_select,$connect);
$array = mysql_fetch_array($select);


        $query = "INSERT INTO palpites (nome,email,palpites,palpites2,palpites3) VALUES ('$nome','$email','$palpites','$palpites2','$palpites3')";
        $insert = mysql_query($query,$connect);

?>
<script>

alert("Seus Palpites Foram Gravados Com sucesso.") ;

</script>

// volta pra lá

<?PHP

header("Refresh: 0; http://localhost/bolao/home/palpitar.php");

?>

I would like to know how to limit a person from sending the form with the same email.

    
asked by anonymous 06.03.2018 / 19:00

1 answer

1
$query_select = mysql_query("SELECT email FROM palpites WHERE 'email' = '".$_POST['email']."'") or exit(mysql_error());
if(mysql_num_rows($query_select)) {
    exit('Email já existe');
}
  

mysql_num_rows () returns the number of rows in a result. This command is valid only for SELECT.

As already stated in your question Sending only the id mysql functions, are deprecated, removed from PHP 7. Use mysqli or PDO.

    
06.03.2018 / 19:45