I am working on an app in ionic that needs to post user submitted info to a database. I am working with someone who has created a separate php script for this form submission, however each time I try post from the app I am either getting cors issues when not using a proxy or a 404 error when using json afeld...
The PHP looks like this:
<?php
$data = json_decode(file_get_contents("php://input"));
$celeb = $data->celeb;
$camp = $data->camp;
$spirit = $data->spirit;
$sport = $data->sport;
$bizs = $data->bizs;
$entrep = $data->entrep;
$young = $data->young;
$conser = $data->conser;
$saty = $data->saty;
$name = $data->name;
$surname = $data->surname;
$email = $data->email;
$contacts = $data->contacts;
$con = mysql_connect('localhost', 'yarp', 'arpi');
mysql_select_db('yeah', $con);
$qry_em = 'select count(*) as cnt from users where email ="' . $email . '"';
$qry_res = mysql_query($qry_em);
$res = mysql_fetch_assoc($qry_res);
if ($res['cnt'] == 0) {
$qry = 'INSERT INTO test (celeb,camp,spirit,sport,bizs,entrep,young,conser,saty,name,surname,email,contacts) values ("' . $celeb . '","' . $camp . '",' .$spirit . ','.$sport. ','.$bizs. ','.$entrep. ','.$young. ','.$conser. ','.$saty. ','.$name. ','.$surname. ','.$email. ','.$contacts. ')';
$qry_res = mysql_query($qry);
if ($qry_res) {
$arr = array('msg' => "Submitted Successfully!!!", 'error' => '');
$jsn = json_encode($arr);
print_r($jsn);
} else {
$arr = array('msg' => "", 'error' => 'Error In Submit');
$jsn = json_encode($arr);
print_r($jsn);
}
} else {
$arr = array('msg' => "", 'error' => 'A submit has already been cast using this email');
$jsn = json_encode($arr);
print_r($jsn);
}
?>
my controller looks like this:
.controller('FrmController', function ($scope , $http) {
$scope.errors = [];
$scope.msgs = [];
$scope.vote = function() {
$scope.errors.splice(0, $scope.errors.length);
$scope.msgs.splice(0, $scope.msgs.length);
$http.post('https://jsonp.afeld.me/?url=http://www.examplesite.com/submit.php', {
'celeb' : $scope.celeb,
'camp' : $scope.camp,
'spirit' : $scope.spirit,
'sport' : $scope.sport,
'bizs' : $scope.bizs,
'entrep' : $scope.entrep,
'young' : $scope.young,
'conser' : $scope.conser,
'saty' : $scope.saty,
'name' : $scope.name,
'surname' : $scope.surname,
'email' : $scope.email,
'contacts' : $scope.contacts
}
).success(function(data, status, headers, config) {
if (data.msg != '')
{
console.log(data.msg);
$scope.msgs.push(data.msg);
}
else
{
console.log(data.error);
$scope.errors.push(data.error);
}
}).error(function(data, status) {
$scope.errors.push(status);
});
}
})
The submit.php file is definitely at the address so I am not too sure where I am going wrong...