need help with validation


#1

I have done everything and everithing is working fine . adding the comments when logged in etc. I really need help if email and login user are in exsits DB?
Can you help me with this my code please.
Thank you

[php]if(isset($_POST[‘submit’])){
$login2=filter_var($_POST[‘login’], FILTER_SANITIZE_STRING);
$imie2=filter_var($_POST[‘imie’], FILTER_SANITIZE_STRING);
$haslo22=filter_var($_POST[‘haslo2’], FILTER_SANITIZE_STRING);
$haslo2=filter_var($_POST[‘haslo’], FILTER_SANITIZE_STRING);
$email2=filter_var($_POST[‘email’], FILTER_SANITIZE_STRING);

           $login=addslashes($login2);
           $imie=addslashes($imie2);
           $haslo=addslashes($haslo2);
           $haslo2=addslashes($haslo22);
           $email=addslashes($email2);

//proceed with code here

      if($haslo != $haslo2){
             $_SESSION['error']="<span style='color:red'>hasla nie sa identyczne</span>";
          }
           elseif((strlen($imie))<3 || (strlen($imie))>20){
             $_SESSION['name']="<span style='color:red'>Imie musi miec conajmniej 3 znaki nie wiecej niz 20</span>";
          }
     
      else{
          
	$ip=$_SERVER["REMOTE_ADDR"];
	
     $stmt = $connection->prepare("INSERT INTO rejestracja (login, haslo, imie, email, ip) VALUES (?,  ?,?, ?, ?)");

$stmt->bind_param(“sssss”, $login, $haslo, $imie, $email, $ip);
$stmt->execute();

$_SESSION[‘email’]=$email;

header(‘Location:rejestracja_thanks.php’);
}
}
$stmt->close();
$connection->close();
}

?>[/php]


#2

Add a unique constraint to the table