0
This is the first time I have contact with PHP, and I wanted to know how I could make the system recognize an invalid login and instead redirect the user to the homepage (as 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 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>
Only with this information is not possible to help you. Include the form.
– Netinho Santos
I will edit the post
– lua kim
Change the
Location: ../index.php
to direct to the page you want and search about flash messages to see how to display the error message.– Woss