As the title says my PHP/ MySQL query not executing
Can some have a look what am doing wrong ?
$name = ((isset($_POST['name']))?sanitize($_POST['name']):'');
$email = ((isset($_POST['email']))?sanitize($_POST['email']):'');
$password = ((isset($_POST['password']))?sanitize($_POST['password']):'');
$confirm = ((isset($_POST['confirm']))?sanitize($_POST['confirm']):'');
$errors = array();
if($_POST){
$emailQuery =$db->query("SELECT FROM users1 WHERE email = '$email'");
$emailCount = mysqli_num_row($emailQuery);
if($emailCount != 0){
$errors[] = 'That email already exists in our database.';
}
$_POSTwill always exist because it is a superglobal; useif($_POST['email'])at the very least. You don't need to declare yourmysqli_num_rowsif you are only going to use it once:if(mysqli_num_rows($emailQuery)){$error[]...}. And finally, you should be using a prepared statement to protect against injection.mysqliyou should be using parameterized queries andbind_paramto add user data to your query. DO NOT use manual escaping and string interpolation or concatenation to accomplish this because you will create severe SQL injection bugs. Accidentally unescaped data is a serious risk. Using bound parameters is less verbose and easier to review to check you’re doing it properly.