im trying to make a basic http post request that INSERT data to my DataBase. i have the pages:
register.php
that have the register form.maincons.js
that have the controllers of the appliction.sqlregister.php
that have the INSERT query.
im using MeekroDB (libary of sql functions).
the appliction insert the data to the database, but the success function dosn't work.
register.php:
<!doctype html>
<html lang="he" dir="rtl">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="../css/style.css">
<script src="../js/angular.min.js"></script>
<title>register</title>
</head>
<body>
<div ng-app="appRegister" ng-controller="conRegister" class="grid">
<form name="register" method="post" class="col-4 regform" ng-submit="valfunc()">
<input type="text" name="fname" ng-model="fname" required>
<input type="email" name="email" ng-model="email" required>
<input type="submit" value="register">
</form>
</div>
<script src="../js/maincons.js"></script>
</body>
</html>
maincons.js:
var app = angular.module('appRegister', []);
app.controller('conRegister', function($scope,$http) {
$scope.valfunc = function () {
$http.post(
"sqlregister.php", {
'fname': $scope.fname,
'email': $scope.email
}
).success(function(data){
alert(data);
})
.error(function(data){
alert(data);
})
}
});
sqlregister.php:
<?php
require_once '../system/sqlfunc.php';
$info = json_decode(file_get_contents("php://input"));
if(count($info) > 0) {
$fname = $info->fname;
$email = $info->email;
$query=DB::insert('tbcustomers', [
'Custname' => $fname,
'email' => $email
]);
if($query==1)
echo "true";
else
echo "false";
}
?>
the problem is that the success function dont alert the data.
thanks for the helpers.