我有一个ajax,它触发一个名为update和insert查询的函数。当我从数据库中检查时,我意识到只有update查询在运行,但是insert查询从未运行。下面的代码还显示了我的insert查询是正确的。
我的代码有什么问题,为什么更新查询和插入查询不能工作?
users.php
$('#click').click(function () {
var age = 12
$.ajax({
url: '<?php echo base_url('users/demand'); ?>',
data: '&age='+age,
type: 'POST'
}).done(function (result) {
var obj = $.parseJSON(result);
$.each(obj, function (index, element) {
$.ajax({
url: '<?php echo base_url('users/supply'); ?>',
data: '&number='+element.phone+'&email='+element.email+'&age='+element.age,
type: 'POST'
}).done(function (result) {
//refresh page for changes
});
});
});
});
function supply()
{
$value = $_POST['age'];
$query="update table SET `status` = 0 WHERE age IN ($value)";
$this->db->query($query);
$save_query="INSERT INTO table(`status`)VALUES ($value)";
$this->db->query($save_query);
}发布于 2019-07-03 14:42:42
试图在查询之间添加此内容
$this->db->reset_query();比如:
function supply()
{
$value = $_POST['age'];
$query="update table SET `status` = 0 WHERE age IN ($value)";
$this->db->query($query);
$this->db->reset_query();
$save_query="INSERT INTO table(`status`)VALUES ($value)";
$this->db->query($save_query);
}或
function supply() {
$value = $this->input->post('age');
$this->db->where_in("age", $value);
$this->db->update("table", array("status" => 0));
$this->db->reset_query();
$this->db->insert("table", array("status" => $value));
}https://stackoverflow.com/questions/56871946
复制相似问题