How can i check if email or username already exist in my mysql database while another user is registering so i could stop the registration process and possible suggest another 2/3 new username that does not exist in the database for the new user.
so i tried working around and i could only get the one that check if email already exist in database meanwhile i need the one that will check for both username and email in database and print both $error separately. I mean if email exist and username does not exist it will only print the Error email and same for username.
I hope someone understand me.
<?php
if(isset($_POST['register'])) {
$username = $_POST['username'];
$full_name = ucwords($_POST['full_name']);
$email = $_POST['email'];
$password = trim($_POST['password']);
$time = time();
$age = $_POST['age'];
$gender = $_POST['gender'];
// Geolocation
$longitude = $_SESSION['longitude'];
$latitude = $_SESSION['latitude'];
$geo_info = $geo->getInfo($latitude,$longitude);
$city = $geo_info['geonames'][0]['name'];
$country = $geo_info['geonames'][0]['countryName'];
$check_d = $db->query("SELECT username, email from users WHERE username = '$username' OR email = '$email'");
$check_d = $check_d->num_rows;
if($check_d == 0) {
$db->query("INSERT INTO users (profile_picture,username,full_name,email,password,registered,credits,age,gender,ip,country,city,longitude,latitude) VALUES ('default_avatar.png','$username','$full_name','$email','".$auth->hashPassword($password)."','$time','100','$age','$gender','$ip','".$country."','".$city."','".$longitude."','".$latitude."')");
setcookie('justRegistered', 'true', time()+6);
setcookie('mm-email',$email,time()+60*60*24*30,'/');
header('Location: '.$domain.'/people');
}
else { $error = 'Username or password already exist, Try Another';
}
}
if($auth->isLogged()) {
$first_name = $system->getFirstName($_SESSION['full_name']);
$logged_in_user = header('Location: '.$domain.'/people');
}
$users = $db->query("SELECT * FROM users ORDER BY RAND() LIMIT 7");
?>