I have this Angular code in a function:
function doAjax() {
$http({
method: 'POST',
url: 'http://thatsmyipv4address/MarkBeacons/www/test.php',
data: {
'dispositivo': getDevice(),
'momentoacceso': getMomentoExacto()
}
})
.then(function (data) {
alert("Data Saved: " + data.response);
console.log(data);
}, function (error) {
//alert('error: ' + error);
console.log('error: ' + error.data);
});
}
And when I call doAjax() it must send a POST message to my test.php with the values of getDevice() that returns an String and getMomentoExacto() that returns another String.
But when I execute the test.php:
$link = mysqli_connect("localhost", "root", "", "markbeacons");
if(isset($_POST['dispositivo'])) {
$dispositivo = $_POST['dispositivo'];
} else {
$dispositivo = 'valor1';
}
if(isset($_POST['momentoacceso'])) {
$momentoacceso = $_POST['momentoacceso'];
} else {
$momentoacceso = 'valor2';
}
echo "$dispositivo";
echo "$momentoacceso";
$sql = "INSERT INTO registroEstimote (dispositivo, momentoconexion) VALUES ('$dispositivo', '$momentoacceso');";
Why it's inserting me on the data base the else values (valor1 and valor2)?
test.php. also if yourtest.phpis in the root folder of your project you can just useurl: '/test.php'