hey guys im getting the account to delete only if i Put the correct user name and Password but suppose the user enters a wrong user name and Password to delete an account i want a message to disPlay saying wrong username or Password. i tried this but im not getting it to echo the message "wrong username or password "if the user enter a wrong user name and Password my code <?php include ('connect.php'); if (isset($_POST["submit"])){ $user = $_POST['u_name']; $pass = $_POST['pwd']; if(!$user){ echo "please enter your username. <br>"; } if(!$pass){ echo "please enter your password"; header('Refresh: 9; deleteform.php'); } if ($user && $pass){ $sql= ("DELETE FROM user_accounts WHERE username = '$user' AND password = '$pass' "); $res = mysql_query($sql); echo"your account has been deleted"; } ELSE { echo"invalid username and password"; } } ?> PHP:
- Well, first of all, you need to sanitize your $_POST. See This. (for security purposes) - You can check if that DELETE query was sucessfully by calling "mysql_affected_rows()" function. If it returns 1, then the username and password were correct. Otherwise, invalid. ... $res = mysql_query($sql); if (mysql_affected_rows() == 1) echo "your account has been deleted"; else echo "invalid username and password"; Code (markup): - Also, you can put 'limit 1' at the end of the sql, i don't know how your database is structured, but that little change could increase speed. $sql= ("DELETE FROM user_accounts WHERE username = '$user' AND password = '$pass' LIMIT 1"); Code (markup):