I have an ajax which triggers a function called which runs an update and insert query. When i check from my db, i realise only the update query is running but then, the insert query never runs. The code below also shows my insert
query to be correct.
What could be the issue with my code why the update query works and insert query doesn't work?
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);
}