I am creating a registration form and trying to get the source of registration of the user, my code is given below.
The issue is the registration form only work with AND condition and not with OR condition, please have a look into my code and suggest what needs to be modified
I am not taking sql injection protection into consideration as of now hence didn't used PDO
<?php
try{
include 'connection.php';
$con = mysqli_connect($servername,$username,$password,$database);
$json = file_get_contents('php://input');
$obj = json_decode($json,true);
$uqid = md5(uniqid().mt_rand());
$fullname = $obj['fullname'];
$email = $obj['email'];
$emailformat = filter_var($email, FILTER_VALIDATE_EMAIL);
$profilePic = $obj['profilePic'];
$password = $obj['password'];
$source = $obj['source'];
if(empty($email) || !$emailformat){
echo json_encode('Email issue');
exit();
}
//Checking if user is already registered
$CheckSQL = "SELECT * FROM users WHERE email='$email'";
$check = mysqli_query($con,$CheckSQL);
$row = mysqli_fetch_array($check, MYSQLI_ASSOC);
$count = mysqli_num_rows($check);
if($count == 1 AND $source == "Google" OR $source == "Facebook"){
//login register
echo json_encode("User login successfully");
exit();
}
else{
//register new user
$Sql_Query = "INSERT INTO users (uqid, fullname, email, profilePic, password, source,registerDate) values ('$uqid', '$fullname', '$emailformat', '$profilePic', '$password', '$source', NOW())";
}
if(mysqli_query($con,$Sql_Query)){
echo json_encode("User registered successfully");
exit();
}
}
catch (\Exception $ex) {
die($ex->getMessage());
}
?>