Reputation: 440
I have no knowledge in CodeIgniter and would like some help. Here in the company where I work, there is a kind of booking system for dresses rental, so, the brides need to schedule a datetime through the online system before going to a store. That script was written with Codeigniter and what is the error: some records are being duplicated in database, I mean, the id keeps different, however in admin the same customer is being shown scheduled to the same datetime 4, 5 times, whatever. This is the code to create/insert a schedule in database:
$agendamento = Agendamento::create(array(
'loja_id' => $this->input->post('loja_id'),
'usuario_id' => $this->input->post('usuario_id'),
'datahora' => $this->input->post('datahora'),
'loja' => $loja->nome,
'ultima_alteracao' => date('Y-m-d h:j:s'),
'status' => 'D-2'
));
The above data comes through an ajax request, here:
$('#confirma_agendamento').on('click touchstart', function() {
$.ajax({
"dataType" : "text",
"type" : "POST",
"data" : {
"loja_id" : loja_selecionada,
"lista_espera" : lista_espera,
"usuario_id" : usuario_id,
"datahora" : data_selecionada + " " + hora_selecionada + ":00:00",
//"vestidos" : $("#vestidos").val()
},
"url" : base_url + 'ajax/lojas/agendar',
"success" : function (retorno) {
if (retorno == '1') {
window.location = SITE_URL + 'meus_agendamentos';
}
else {
showModal('<h1>Erro</h1><p>Houve algum problema com o seu agendamento. Por favor tente novamente em alguns instantes.</p>');
}
},
"error" : function() {
showModal('<h1>Erro</h1><p>Houve algum problema com o seu agendamento. Por favor tente novamente em alguns instantes.</p>');
}
});
});
So, my question is: how to prevent duplicated records by datetime, I mean, avoid 2 records for the same datetime in codeigniter?
Upvotes: 1
Views: 63
Reputation: 2202
in your ajax request url "url" : base_url + 'ajax/lojas/agendar', menas in ajx controller lojas method stay , you first need check the data which is already stay in or not in database . if data is found then not insert and if the data is not stay in database then write insert query
Upvotes: 1