How do I check if the email is already in use? If in use, the user will be alerted that email is already used, if not, it would proceed.
here in my codes, it did not work, it still registered even if i inputted the same email.
<?php
session_start();
$con=@mysql_connect("localhost","root","secretpassword");
$dbcheck = mysql_select_db("buybranded");
if (!$dbcheck) {
echo mysql_error();
}
$new_email= $_POST['email'];
$xxx = mysql_query("SELECT email FROM users WHERE email = $new_email");
$yyy = mysql_fetch_row($xxx);
if(!isset($yyy['email'])){
$hashed_password = hash( 'sha512', $_POST['password'] );
$type="customer";
$sql="INSERT INTO users(first_name, middle_name, last_name, gender, email, password, birth_date, home_address, postal_code, home_phone, mobile_phone, source, type)
VALUES
('$_POST[first_name]','$_POST[middle_name]','$_POST[last_name]','$_POST[gender]','$_POST[email]','$hashed_password','$_POST[birth_date]','$_POST[home_address]','$_POST[postal_code]','$_POST[home_phone]','$_POST[mobile_phone]','$_POST[source]','$type')";
}
else {
echo "hahaha";
}
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error($con));
}
header('refresh: 0; url=../index.php#openModal');
$message = "You are now Registered, Please Sign In.";
echo("<script type='text/javascript'>alert('$message');</script>");
?>
I hope you guys can help, i am new with php. :) thank you!