Good afternoon! Im trying to make registration on my web page and i have an issue - registration is happening, but it can create multiple users with same symbols and also same e-mails and dont giving error when passwords dont match.
Here is form -
<form action = "register.php" method = "post">
Select username:<br>
<input type = "text" name = "username"><br>
Your e-mail:<br>
<input type = "email" name = "email"><br>
Set password:<br>
<input type = "password" name = "password1"><br>
Repeat password:<br>
<input type = "password" name = "password2"><br>
<button> </button>
</form>
and here is PHP code -
<?php
if (isset($_POST['username']) && isset($_POST['email']) && isset($_POST['password1']) && isset($_POST['password2'])){
$query = 'select * from users where username = "'.addslashes($_POST['username']).'"';
$numrows = mysqli_num_rows($link,$query);
if($numrows == 0){
$query_mail = 'select * from users where email = "'.addslashes($_POST['email']).'"';
$numrows_mail = mysqli_num_rows($link,$query_mail);
if($numrows_mail == 0){
if(isset($_POST['password1']) == isset($_POST['password2'])){
$sql = 'INSERT INTO users (username,password,email) VALUES("'.addslashes($_POST['username']).'","'.addslashes($_POST['password1']).'","'.addslashes($_POST['email']).'")';
$result = mysqli_query($link,$sql) or die(mysqli_error($link));
if($result){
echo 'Account sucsessfully created! You can now log in.';
}else{
var_dump($result);
}
}else {
echo 'Passwords must match!';
}
}else {
echo 'E-mail allready registered!';
}
}else{
echo 'Username allready in use!';
}
}
?>
Can someone explain what is incorrect here?