5
I’m doing some object orientation exercises in PHP and when changing the database data, I come across the following error
Catchable fatal error: Object of class mysqli_result could not be converted to string in /var/www/html/Student/class/Alunodao.php on line 30
I’ve never seen him before (in my long career of a few months). Can anyone tell me what it means?
Just follow my code
Altera-data.php
$id = $_POST['id'];
$nome = $_POST['nome'];
$cpf = $_POST['cpf'];
$senha = $_POST['senha'];
$alunoDAO = new AlunoDAO();
$nome_imagem = $alunoDAO->buscaFoto($conexao, $id);
$aluno = new Aluno($nome, $cpf, $senha, $nome_imagem);
$alunoDAO->alteraDados($conexao, $aluno, $id);
and my function in the class AlunoDAO
(the one being pointed out an error).
function alteraDados($conexao, $aluno, $id){
$senhaMD5 = md5($aluno->getSenha());
$query = "update alunos set nome = '{$aluno->getNome()}', cpf = '{$aluno->getCpf()}', senha = '{$senhaMD5}', imagem = '{$aluno->getNomeImagem()}' where id = {$id}";
$resultado = mysqli_query($conexao, $query);
return $resultado;
}
Which line is the error?
– rray
on the $query line
– Naldson
Some of the values passed are object and not a string, print the query.
– rray
What do you mean, rray?
– Naldson
ago
echo $query;
– rray
All the right values appear?
– rray
ah, I had done it and it does not return me anything. I went to the page where the error appears, I went to the class link and nothing.
– Naldson
Let’s go continue this discussion in chat.
– rray
Look, I’m gonna post an answer, put it in your script, and then say what it came back to.
– Edilson