gpt4 book ai didi

php - 如何防止重复记录?

转载 作者:行者123 更新时间:2023-11-28 23:57:25 25 4
gpt4 key购买 nike

我不了解 CodeIgniter,需要一些帮助。在我工作的公司,有一种礼服租赁的预订系统,所以,新娘们需要在去商店之前通过在线系统安排约会时间。该脚本是用 Codeigniter 编写的,错误是什么:一些记录在数据库中被复制,我的意思是,id 保持不同,但是在管理员中,同一客户被安排在相同的日期时间 4、5 次,等等。这是在数据库中创建/插入计划的代码:

$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'
));

以上数据是通过ajax请求过来的,这里:

$('#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>');
}
});
});

所以,我的问题是:如何防止按日期时间重复记录,我的意思是,在 codeigniter 中避免同一日期时间出现 2 条记录?

最佳答案

在你的 ajax 请求 url "url": base_url + 'ajax/lojas/agendar', ajx controller lojas method stay 中,你首先需要检查数据库中已经存在或不存在的数据。如果找到数据则不插入,如果数据不在数据库中则写入插入查询

关于php - 如何防止重复记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31249987/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com