1
Staff with a problem in this code snippet, it evaluates if there is a variable $_POST['employee_id']
if it exists it will give an update, if it does not exist an Insert! until then everything is fine working, but if I give an update and then give an update it runs the update instead of the Insert, I think because the variable $_POST['employee_id']
must have been in memory, remembering that all this occurs via ajax without refresh on the page, I already researched about it and could not solve already try to give unset
in $_POST
setala as a null array, as you can come... however nothing worked, I thank you from now!
// Se update
if(isset($_POST['employee_id']) AND $_POST['employee_id'] != '') {
$id = $_POST['employee_id'];
$user = Container::getModel("Client");
$this->view->clients = $user->update($data, $id);
if(isset($this->view->clients)){
unset($_POST['employee_id']);
$_POST = array();
echo json_encode(["update"=>true,"msg"=>"Cadastro atualizado com <strong>sucesso!</strong>"]);exit;
}else{
echo json_encode(["status"=>false,"msg"=>"Desculpe ocorreu um<strong> Erro!</strong>"]);exit;
}
// Se não insert
}else{
$user = Container::getModel("Client");
$this->view->clients = $user->insert($data);
if(isset($this->view->clients)){
$this->view->last_client = $user->find($this->view->clients);
echo json_encode(["insert"=>true,"msg"=>"Cadastro realizado com <strong>sucesso!</strong>","clients"=>$this->view->last_client]);exit;
}else{
echo json_encode(["status"=>false,"msg"=>"Desculpe ocorreu um<strong> Erro!</strong>"]);exit;
}
}
It’s not because the
unset
in theinsert
also?– Leonardo Pessoa
in case it evaluates this before falling into the Insert, only if the
$_POST['employee_id']
not exist that it falls in the Insert, if I reload the page and give an insert it normally inserts, the problem is after the first update, then the Insert becomes update.. kkk– wDrik