This is the first time I have contact with PHP, and was wondering how I could make the system recognize an invalid login and instead of redirecting the user to the home page (as it is happening), empty the filled field and display a message warning that the login is incorrect.
PHP (the code is bigger, but I put the part that I think is important):
if (isset ($_POST ['enviar'])){// se o campo enter for clicado
$username=$_POST['username'];
$senha=$_POST['senha'];
$query = @mysql_query ("SELECT * FROM cadastro WHERE username='$username' AND senha ='$senha'"); // Verifique no banco se o login e a senha digitados existem.
$conta = @mysql_num_rows ($query);// conte os dados do banco selecionados na variável query
if ($conta == '0') {// se o valor digitado não existir
echo "<script language= 'javascript'> window.alert('Os campos não correspondem');</script>";
header ("LOCATION: ../index.php");
}else{
while ($resultado= @mysql_fetch_array($query) ){
FORM:
<form id="form2" name="form2" method="post" action="php/usuarioautenticado.php">
<input type="text" name="username" id="username" required="required" placeholder="Usuário"/>
<input type="password" name="senha" id="senha" required="required" placeholder="Senha"/>
<input type="submit" name="enviar" id="enviar" value="Enviar" />
</form>