Limit sending the same email in the form?

Asked

Viewed 89 times

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 registering.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 so that a person does not send the form with the same email.

  • Please put a Minimum, complete and verifiable example so that we can give a more appropriate response.

  • Was corrected my question.

  • If I understand you want the email to be a single key (can’t have two equal), then before registering the form data you need to search the database if there is an email already registered with the amount sent in the form

  • Exact @Guilhermecostamilam.

  • Accepting an answer is important because it makes it clear to other users that your problem is solved, and how it was solved. At the same time, it rewards the author of the best answer for having solved his problem. Learn how to accept a reply in https://pt.meta.stackoverflow.com/questions/1078/como-e-por-que-aceitar-uma-resposta/1079#1079

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 only valid for SELECT.

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.