So I am trying to send an $http angularjs request to php but the it will trigger successCallback (so does that mean that my request is successful?) but when I checked my database nothing happened and my data is still there. I know I'm missing something in here. please help.
Controller (which calls the checkPollCodeIfAvail function)
pollFactory.checkPollCodeIfAvail('qwe123').then(function successCallback(response){
console.log('success');
}, function errorCallback(response){
console.log('fail');
});
Factory:
factory.checkPollCodeIfAvail = function(x){
code = x;
return $http({
method: 'POST',
data: {
'action' : 'checkPollCode',
'pollCode' : code
},
url: 'http://localhost/poll/api.php'
});
};
return factory;
api.php
if(empty($_POST['action'])){
return;
}
if(($_POST['action']) == "checkPollCode"){
$checkPollCode = $_POST['pollCode'];
}
switch ($_POST['action']) {
case 'checkPollCode':
$sql = "DELETE FROM polls WHERE pollCode = :pollcode";
$stmt = $db_con->prepare($sql);
$stmt->bindParam(":pollcode", $checkPollCode);
$stmt->execute();
if($stmt->rowCount() > 0){
echo "success";
}else{
echo "error";
}
break;
}
Thank you for anyone that can help me.
GETbut in php isPOSTPOSTbut it still won't work.successCallbackin angularusedswitch since I will be having a few actions in my php file. Why do I have to removesuccessCallback?