I am an angular begginer, and I am currently trying to save some data in a data base with the $http() service, but it does not work. Could you help me, please? This is what I am trying to do:
Form:
<form name="form">
<input ng-model="model.text" type="text" name="text">
<button class="button" ng-click="saveData()"> Save </button>
</form>
Controller of that page:
.controller('pagCtrl', function ($scope, $http) {
$scope.saveData = function () {
$http ({
url : 'http://localhost/prueba/www/php/enviar_datos.php',
method : 'POST',
data : { text : $scope.form.text.value }
}).then (function (response) {
}, function (response) {
});
}
})
PHP:
<?php
$link = mysqli_connect("localhost", "root", "", "testDB");
if (mysqli_connect_errno()) {
die("Error de conexión: " . mysqli_connect_error());
}
mysqli_set_charset($link, 'utf8');
mysqli_query($link, "INSERT INTO tabla_prueba (texto) VALUES ('" . $_POST['text'] . "')");
mysqli_close($link);
?>
I think the problem is that it does not connect correctly to the php url. I am working with Ionic. Thank you for your attention!