4
I am trying to carry out the UPDATE, but gives the following error:
Notice: Undefined index: id in C: wamp www Sitephp base updateFunctioning.php on line 4. Follow my code
Function
function atualizar(id){
if(confirm("Deseja atualizar o registro?")){
location.href = 'atualizarFuncionario.php?id=' + id;
}
}
php record.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="css/estilo.css">
<script src="JS/func.js"></script>
<script src="JS/jquery-3.2.1.min.js"></script>
</head>
<body>
<p class="cab">ALTERAÇÃO DE FUNCIONÁRIOS</p>
<form action="base/atualizarFuncionario.php" method="POST">
<?php
require_once './base/conexao.php';
$funcionario = filter_input(INPUT_GET,"id");
$nome_alter= filter_input(INPUT_GET,"nome");
$cpf_alter= filter_input(INPUT_GET,"cpf");
$tel_alter= filter_input(INPUT_GET,"tel");
?>
<center> <input type="text" id="inp" name="nome" size="40" value="<?php echo $nome_alter;?>" required="" placeholder="Nome" ><br><br>
<input type="text" name="cpf" id="inp" size="40" id="cpf" required="" value="<?php echo $cpf_alter;?>" maxlength="14" onkeyup="mascCPF(this.value)" placeholder="CPF xxx.xxx.xxx-xx"><br><br>
<input type="text" name="tel" id="inp" size="40" value="<?php echo $tel_alter;?>" id="tel" required="" maxlength="14" onkeyup="mascTel(this.value)" placeholder="Telefone(xx)9xxxx-xxxx"><br><br>
<a href="#" onclick="atualizar(<?php $funcionario = $_GET['id'];?>)"><button type="submit">ATUALIZAR</button></a></center>
</form>
<center> <a href="base/listarFuncionario.php"><input type="submit" value="Listar"</a> </center>
</body>
</html>
updateFuncture.php
include_once './conexao.php';
$id = $_GET['id'];
$nome = $_POST['nome'];
$cpf = $_POST['cpf'];
$telefone = $_POST['tel'];
$atualizar = "UPDATE funcionario SET nome='$nome', tel = '$telefone', cpf= '$cpf' WHERE id= '$id'";
$atualizar = $PDO->query($atualizar);
if($atualizar){
echo "<script>alert('Funcionario atualizado com sucesso!'); </script>";
} else {
echo "<script>alert('Erro ao atualizar'); </script>";
//location.href = '../formCadastro.php';
}
indicate which code refers to the.php registry file, for ease
– Victor
The one in the middle, where it contains my form
– Ruan Rodrigues
ok I’ll edit the question, accept the edit so I fix some details
– Victor
method="POST" you are sending the form as POST and waiting for the parameter as GET, that’s right?
– arllondias
Yes, because when I put to receive the parameter as POST it from the error
– Ruan Rodrigues
Dude, you send POST and try to catch GET doesn’t make any sense. It’s never gonna work
– gabrielfalieri
and that
base/
, All right, METHOD of FORM??– William Aparecido Brandino
Yes, it is the path of my file updateFunctioning.php
– Ruan Rodrigues
Note that you do not need to indicate which page will go in your type=Submit, it already recognizes this by the action, follow my code that will totally work
– Victor