0
I’m trying to create a basic login, with verification so that there are no records with even users in the database. But I’m making a mistake on this line $row = $resulta->fetch_assoc();
Fatal error: Uncaught Error: Call to a Member Function fetch_assoc() on Boolean in...
$result = "SELECT * FROM usuario WHERE usuario = '$usuario' AND senha = '$senha' ";
$resulta = $conn->query($result);
$row = $resulta->fetch_assoc();
if ($resulta->num_rows > 0) {
echo "<script>alert('Usuário Já Existente');</script>";
} else {
$result = "INSERT INTO Cadastro (usuario, senha, nivel_acesso) VALUES ('$usuario', '$senha', '$nivel_acesso')";
$resultado = mysqli_query($conn, $result);
}
Does anyone know how to fix this so that there is user verification before entering into the bank ?
The $query is invalid
– Sveen
wouldn’t be: $result->mysqli_fetch_assoc() ?
– AnthraxisBR
@Anthraxisbr also did so, but no way works. I wanted to check if there is already a registered user name in the bank, if yes alert user and otherwise enter in the bank... but is giving error
– Victor
@Anthraxisbr, no. The guy is using the object-oriented method of mysqli. https://secure.php.net/manual/en/mysqli-result.fetch-assoc.php
– Phiter
$results is false @Anthraxisbr
– Sveen
@Sveen would have some other logical way to make it work ?
– Victor
if ($result->num_rows > 0) ? while($Row = $result->fetch_assoc()) ? ..... try doing a while while
– Arsom Nolasco
Table name and fields are correct? Remember that it is case sensitive
– Sveen
@Arsomnolasco $result is false, not a valid object
– Sveen
try with SELECT u.* FROM user u WHERE u.user LIKE '$user' AND u.password LIKE '$password'
– Sveen
usuario='{$usuario}' so try in password tbm
– Arsom Nolasco
I think Mysql can confuse the name of the field "user" with the table "user"
– Sveen
The code posted works perfectly well. I tested it on my server. The problem may be in the part of the code not posted.
– user60252
@Victor tests my answer and give me a return
– Woton Sampaio
It is necessary to post complete code, connection and table structure so that someone can identify the problem because as I commented before, the code posted works perfectly well on my server.
– user60252
Just so we’re clear, the code you have is susceptible to attacks from mysql Injection. Something to consider later after solving the problem.
– Isac
@Leocaracciolo is right. The problem is probably related to the other part of the code.
– Andrei Coelho
Thanks to everyone who helped, I developed the code quickly and was moving from the old PHP to PHP 7, I ended up getting so caught up that I created a.select condition for a table other than the one I wanted for my Insert. The error is in the select of the same table, should be select * from Register
– Victor