0
This code cannot find the records, and brings that variable $lista
is undefined.
My HTML:
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<?php
include_once '../classes/Sistema2/Administrador.class.php';
?>
<form action="Crud.php" method="post" id="none">
<input type="hidden" name="acao" id="acao" value="<?php echo isset($_GET["id"])?'atualizar':'';?>">
Nome:<input type="text" id="none" name="nome" value="<?php echo $lista['nome']?>">
email:<input type="text" id="none" name="email" value="<?php echo $lista['email']?>">
cpf:<input type="text" id="none" name="cpf" value="<?php echo $lista['cpf']?>">
salario:<input type="text" id="none" name="salario" value="<?php echo $lista['salario']?>">
<input type="submit" value="atualizar" name="atualizar">
</form>
</body>
That code stays in mine Crud.php
and a file it receives from post
and makes the call with the class
Administrador
if(isset($_GET["id"])){
if($_POST["acao"] == "atualizar"):
$administrador = new Administrador();
$administrador->atualizar((strip_tags(trim($_POST['nome']))),(trim($_POST['email'])),(trim($_POST['cpf'])),(trim($_POST['salario'])));
endif;
}
That code is on class
:
public function atualizar($nome,$email,$cpf,$salario){
$sql_atualizar = "UPDATE administrador SET nome=:nome, email=:email, cpf=:cpf salario=:salario WHERE id = :id";
print_r($sql_atualizar);
try{
$query_atualizar = $this->conn()->prepare($sql_atualizar);
$query_atualizar->bindValue(':nome',$nome,PDO::PARAM_STR);
$query_atualizar->bindValue(':email',$email,PDO::PARAM_STR);
$query_atualizar->bindValue(':cpf',$cpf,PDO::PARAM_STR);
$query_atualizar->bindValue(':salario',$salario,PDO::PARAM_STR);
//echo "<script>alert('Administrador alterado com sucesso! ')</script>";
header('location: Index.php');
}catch(PDOException $err){
echo " Erro: ".$err->getMessage();
}
}
Huuum, code review :D. Already comments on that
header()
to begin.– rray