The code verifies that the email exist but it doesn't prevent inserting duplicates in the table. I would like to insert if it doesn't exist, and redirect to thank_you.php - Code looks like this:
<?php
if (isset($_POST['submit'])) {
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$username = $_POST['username'];
$password= password_hash($_POST['password'], PASSWORD_DEFAULT);
$country = $_POST['country'];
$city = $_POST['city'];
$state = $_POST['state'];
$phone = $_POST['phone'];
include 'connect_sql.php';
$sql = "INSERT INTO [Sonic].[dbo].[member] ([firstName],[lastName],[UserName],[Password],[Country],[City],[State],[Phone])
VALUES ('$firstName', '$lastName', '$username', '$password', '$country', '$city', '$state', '$phone')";
$email = "SELECT UserName FROM [Sonic].[dbo].[member] WHERE UserName='$username'";
$row = sqlsrv_fetch_array( $email, SQLSRV_FETCH_ASSOC);
$stmt = sqlsrv_query( $conn, $sql );
if( $row === false) {
echo "<div id='message'> Username $username already exist</div>";
}
else {
header('Location: thank_you.php');
}
}
?>