I am trying to compare if either a user or a password exist in the database before adding the result of the form values to the database. Since there should be a 1:1 relationship to a username and an email with both unique as is traditionally a requirement.
It seems like I am not properly dereferencing the username or password values from the array returned from fetchassoc. Becuase the ifstatement returns a synaxerror regarding []
$username = !empty($_POST['username']) ? trim($_POST['username']) : null;
$password = !empty($_POST['password']) ? trim($_POST['password']) : null;
$query = $pdo->prepare("SELECT * FROM users WHERE username = ? AND email = ? LIMIT 1");
$query->bindParam(1, $username, PDO::PARAM_STR);
$query->bindParam(2, $email, PDO::PARAM_STR);
$query->execute();
$result = $query->fetch(PDO::FETCH_ASSOC);
//wanting to verifying that neither the username nor the email already exist.
if ($result->['username'] !== $username && $result->['email'] !== $email)
{
$query = $pdo->prepare ("INSERT INTO users....")
}
previously my if statement was
if(count((array)$result) == 0)
But nothing was being inserted into the database and I don't think it will work if a user has entered the same email but a different username or vice versa.