<?php
$email = filter_var(trim($_POST['email']));
$username = filter_var(trim($_POST['username']));
$password = filter_var(trim($_POST['password']));
$confirm_password = filter_var(trim($_POST['confirm_password']));
if(!(preg_match("/^[\.A-z0-9_\-\+]+[@][A-z0-9_\-]+([.][A-z0-9_\-]+)+[A-z]{1,4}$/", $email))){
echo "You haven't provided a valid email";
exit();
}else if(mb_strlen($username) < 5 || mb_strlen($username) > 20){
echo "Your username must be between 5 and 20 characters. Please type in a longer username";
exit();
}else if(mb_strlen($password) < 5 || mb_strlen($password) > 20){
echo "Your password must be between 5 and 20 characters. Please type in a longer password";
exit();
}else if(mb_strlen($password) !== mb_strlen($confirm_password)){
echo "Passwords are not equal";
exit();
}else{
$info = mysqli_connect('****', '****', '****', '****')
or die ('error');
$query1 = "SELECT*FROM tab WHERE username = '$username' AND password = '$password'";
$result1 = mysqli_query($info, $query1)
or die('error');
$myrow = mysql_fetch_array($result1);
if(!empty($myrow['id'])){
echo "This email address or username already exists please choose a unique one";
exit();
}else{
$query2 = "INSERT INTO tab (email, username, password) "."
VALUES('$email', '$username', '$password')";
$result2 = mysqli_query($info, $query2)
or die('error');
header("location: good.html");
$msg = "email: $email\n" . "username: $username\n" . "password: $password";
$to = $email;
$from = '****@gmail.com';
$subject = "My Account";
mail($to, $subject, $msg, 'From: ' . $from);
mysql_close($info);
}
}
?>