-1
I’m developing a system for college and I’m having the following problem
Notice: Undefined property: stdClass::$Disciplina in C:\Users\lucas.vianna\Desktop\SGA\db\turmaDAO.php on line 64 Notice: Undefined variable: getDisciplina in C:\Users\lucas.vianna\Desktop\SGA\turmas.php on line 41 Fatal error: Uncaught Error: Method name must be a string in C:\Users\lucas.vianna\Desktop\SGA\turmas.php:41 Stack trace: #0 {main} thrown in C:\Users\lucas.vianna\Desktop\SGA\turmas.php on line 41
Line 41: $disciplina = $resultado->$getDisciplina();
Line 64: $turma->setDisciplina($rs->Disciplina);
Follow the update code on DAO:
public function atualizar($turma){
global $pdo;
try {
$statement = $pdo->prepare("SELECT idTurma, Disciplina_idDisciplina,Nome FROM turma WHERE idTurma = :id");
$statement->bindValue(":id", $turma->getIdTurma());
if ($statement->execute()) {
$rs = $statement->fetch(PDO::FETCH_OBJ);
$turma->setIdTurma($rs->idTurma);
$turma->setDisciplina($rs->Disciplina);
$turma->setNome($rs->Nome);
return $turma;
} else {
throw new PDOException("Erro: Não foi possível executar a declaração sql");
}
} catch (PDOException $erro) {
return "Erro: ".$erro->getMessage();
}
}
Follow the select code in the view
if (isset($_REQUEST["act"]) && $_REQUEST["act"] == "upd" && $id != "") {
$turma = new turma($id, '','');
$resultado = $object->atualizar($turma);
$nome = $resultado->getNome();
$disciplina = $resultado->$getDisciplina();
}
<select name="disciplina"><?php
$query = "SELECT * FROM Disciplina order by Nome;";
$statement = $pdo->prepare($query);
if ($statement->execute()) {
$result = $statement->fetchAll(PDO::FETCH_OBJ);
foreach ($result as $rs) {
if ($rs->idDisciplina == $disciplina) {
echo "<option value='$rs->idDisciplina' selected>$rs->Sigla</option>";
} else {
echo "<option value='$rs->idDisciplina'>$rs->Sigla</option>";
}
}
} else {
throw new PDOException("Erro: Não foi possível executar a declaração sql");
}
?>
</select>
The estate Discipline on the line
$rs->Disciplina
does not exist. The correct is$rs->Disciplina_idDisciplina
– Valdeir Psr
And you don’t need the dollar
$
to call a method, except if you use a variable with the method name, for example:$getDisciplina = "getDisciplina"; $resultado->$getDisciplina()
– Valdeir Psr
Worked thanks!
– Lucas Vianna