I wrote an user action analysis but I can't execute my insert into statement. I tried all suggestion on stack can't but figure out my mistake, I don't even get an error: it is running through without executing the statement. I have also an connection php - this works fine so the fault is not there. I would like to insert the action var later but at first I have to call the function. So whats wrong with my request or php function?
jQuery
$( document ).ready(function() {
var action = '';
document.addEventListener('click', function(e) {
e = e || window.event;
e = e.target || e.srcElement;
if (e.nodeName === 'SECTION') {
action = e.id;
updateAction();
}
}, false);
function updateAction() {
$.ajax({
type: "POST",
url: '../actions/userAction.php',
data: {action: 'test'},
success: function(){
console.log(action);
}
});
}
});
PHP
<?php
class userAction
{
/* User Action */
public function updateAction(){
if(isset($_POST['action']) && !empty($_POST['action'])) {
$db = getDB();
$st = $db->prepare("INSERT INTO user_analysis (action) VALUES ('bla') where userID = 1945");
$st->execute();
$db = null;
$_SESSION['uid']=$uid;
return true;
} else
{
return false;
}
}
}
?>
updateAction()in this function? if entering then check you are getting value in post or not. And also query is wrongINSERTcommand cannot haveWHEREclause. IF you are updating a record, useUPDATEupdateAction()?