Personal with a problem in this code snippet, it evaluates whether there is a $_POST['employee_id']
variable if it exists, it will give an update, if it does not exist in an insert! so if everything is working, but if I give an update and then give an insert it executes the update instead of the insert, I think because the variable $_POST['employee_id']
must have stayed in memory, remembering that it all happens via ajax without refresh in the page, I already researched this and I could not solve already try to give unset
in $_POST
setala as an array null, as you can come ... but nothing worked, Thank you right away!
// 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;
}
}