-1
I am developing a login system, but this error is arresting me and I found no answers so far:
You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use
near '�rios WHERE login = 'admin'' at line 1
I’ll put in the code section to help with the advice:
if(empty($login) or empty($senha)):
$erros[] = "<li> O campo login/senha precisa ser preenchido </li>";
else:
$sql = "SELECT login FROM usuários WHERE login = '$login'";
$resultado = mysqli_query($connect, $sql) or die(mysqli_error($connect)); //mysqli_query($connect, $sql) or die mysql_error();
if(mysqli_num_rows($resultado) > 0):
$senha = md5($senha);
$sql = "SELECT * FROM usuários WHERE login = '$login' AND senha = '$senha'";
$resultado = mysqli_query($connect, $sql);
if(mysqli_num_rows($resultado) == 1):
$dados = mysqli_fetch_array($resultado);
$_SESSION['logado'] = true;
$_SESSION['id_usuário'] = $dados['id'];
header('Location: home.php');
else:
$erros[] = "<li> Usuário e senha incorretos </li>";
endif;
else:
$erros[] = "<li> Usuário inexistente </li>";
endif;
Your table is called
usuários, with same accent? If yes, check the file encodings and database.– Woss
yes, in the database is saved with the accent, and in all parts of the code I reference to it I add the accent too, I am searching for 1 hour and I find nothing :/
– Hugo Melo
Can you enter the full code? Apparently the message is showing that the error is on line 1 (at line 1).
– user144209
I’ll put it in the same comment ? but the line 1 is the opening of php and then has a require_once
– Hugo Melo
<?php //Connection require_once 'db_connect.php'; //Session session_start(); //Send button if(isset($_POST['btn-login']): /Send button $bugs = array(); $login = mysqli_escape_string($connect, $_POST['login']); $password = mysqli_escape_string($connect, $_POST['password']);
– Hugo Melo
this is the beginning of the code (line 1 to line 14)
– Hugo Melo