+ 1
SQL and PHP problem
So what I want to do is make beta keys, basically where if a person enters a key, it will delete it from the column. I just need help deleting it from the database and going through all the things in column to match the key with the posted text from the $_POST method Info: table_name="betakey", column="key" $db="database connection" Code: // beta code if(empty($key)){ $error = "Please enter beta-key."; $check = false; } if($key!==$db->query("SELECT FROM betakey where key=".$key)){ $error = "Invalid beta-key."; $check = false; } if($check == true){ $password = password_hash($password, PASSWORD_BCRYPT); $db->query("DELETE FROM betakey WHERE key=".$key);
1 Resposta
+ 2
You can’t compare pdo query and string because query returns pdo object.
$key !== $db->query(...) is always true
You should count the matching rows.
$query = $db->query(...);
if($query->rowCount() == 0) {
$error = ”Invalid beta-key”;
$check = false;
}