0
I have the following problem. I have a list of records with name, age and phone for example. In each record I have a button to view all the information of this registration.
When I click on this button it takes the user to a next screen that we will call "Data View". When I take the user to this screen I send the ID of this registration to perform the search of other data.
On the "View Data" page I have the following code:
<?php
//Identifica se houve post para a página atual
if (isset($_POST["btnVisualizarPaciente"]) == "btnVisualizarPaciente") {
//Faz requisição do arquivo de classe que realiza a busca dos dados
require_once("class/class_load.php");
$classeLoad = new VisualizarDados();
$request = $classeLoad->requestDados();
}
?>
//HTML para apresentar os dados da busca
<div>Nome: <?php echo $nome; ?></div>
<div>Idade: <?php echo $idade; ?></div>
<div>Telefone: <?php echo $telefone; ?></div>
<div>Endereço: <?php echo $endereco; ?></div>
In the php class file I have the following code
class VisualizarDados {
public function requestDados() {
$idBusca = $_POST['idBusca'];
require_once("inc/database.php");
//SQL Carrega os dados pessoais do paciente
$selectDados = $pdo->prepare(" SELECT * FROM tb_cadastros_sistema WHERE id = :idBusca");
$selectDados->bindParam(':idBusca', $idBusca);
$selectDados->execute();
if ($resultDados = $selectDados->fetch(PDO::FETCH_ASSOC)) {
$nome = $resultDados['nome'];
$idade = $resultDados['idade'];
$telefone = $resultDados['telefone'];
$endereco = $resultDados['endereco'];
}else{
print "Erro ao carregar os dados, por favor contate o suporte";
}
}
}
The code I use to search the data works perfectly, but it does not display the values of the search on the "View Data" page. Is presenting indefinite variable error.
Must be scope problem by error message.
$nome
etc exist only in the methodrequestDados()
the variations of the same name inVisualizar Dados.php
are not the same.– rray
And how could I be solving?
– João Victor
$name = $request ->name; arrow it in main file
– Willian
Your method should return an array with the information. If it is only a record you can do
return $selectDados->fetch(PDO::FETCH_ASSOC);
– rray