0

I implemented a form for the registration of customers, with an email check, which in the registration phase if an email is entered, already registered prevents the registration of that customer, with an alert that warns the user. Until here, no problem. Code:

<?php
$ESITO_POSITIVO = "";
$ESITO_NEGATIVO = "";
$CONTROLLO_PSW = "";

if (isset($_POST['submit'])) {
include '../../connessione.php';

$nome = $connessione->real_escape_string($_POST['nome']);            
$email = $connessione->real_escape_string($_POST['email']);
$cognome = $connessione->real_escape_string($_POST['cognome']);
$password = $connessione->real_escape_string($_POST['password']);     
$confermaPassword = $connessione->real_escape_string($_POST['confermaPassword']);

if ($password != $confermaPassword)
$CONTROLLO_PSW = '<div class="alert alert-danger" role="alert">
  <strong>Attenzione, le Password non coincidono!</strong>
</div>';
else{
$CONTROLLA = mysqli_query($connessione,"SELECT email FROM collaboratori WHERE email='".$email."'");
$SE_IL_RISULTATO_IMMESSO=mysqli_num_rows($CONTROLLA);

if($SE_IL_RISULTATO_IMMESSO==0)  {
$connessione->query("INSERT INTO collaboratori (nome,email,cognome,password) VALUES ('$nome', '$email', '$cognome', '$hash')");
$ESITO_POSITIVO = '<div class="alert alert-success" role="alert">
  <strong>Collaboratore registrato con successo!</strong><br>
  <a href="../../gestisci/utenti/gestisci_utenti.php" type="button" class="btn btn-success">Gestisci i tuoi Collaboratori</a>

</div>';
}
else
{ 
$ESITO_NEGATIVO = '<div class="alert alert-danger" role="alert">
  <strong>Attenzione, il Collaboratore immesso è già stato registrato!</strong>
</div>';
}
}


}
?> 

But now in the test phase I noticed that another problem was born. Let's admit the case I want to register a user with email: test@test.com and this mail has already been registered, I get the error message but if I always write the email: test@test.com inserting a space character or because the user presses the bar or because the copy and paste somewhere in the form, the form itself is as if it were a new mail: test@test.com+ "space" and then I register the email. How can I put a check on this too?

  • 1
    Possible duplicate of [How to validate an email address in PHP](https://stackoverflow.com/questions/12026842/how-to-validate-an-email-address-in-php) – miken32 Dec 03 '18 at 21:16
  • @miken32 I was reading the question of the other user, but I did not understand very much, could you give me an opportunity to move autonomously please –  Dec 03 '18 at 21:20
  • `trim()` will remove extra spaces at the beginning or end of a string –  Dec 03 '18 at 21:26
  • @IdontDownVote perfect sir! i justi fix this with: $email=trim($email); Problem Solved! –  Dec 03 '18 at 21:30

1 Answers1

0

@IdontDownVote in comment solved my problem, with: trim()

in my case: $email=trim($email);