angular/angular.js

cant understand why this error occurs in angularjs PHP JSON. This is my error

suraj-TheDeveloper opened this issue · 2 comments

angular.js:15697 Error: [$http:baddata] http://errors.angularjs.org/1.8.2/$http/baddata?p0=%3Cbr%20%2F%3E%0A%3Cb%3EWarning%3C%2Fb%3E%3A%20%20file_get_contents()%3A%20php_network_getaddresses%3A%20getaddrinfo%20failed%3A%20Temporary%20failure%20in%20name%20resolution%20in%20%3Cb%3E%2Fopt%2Flampp%2Fhtdocs%2Fchatapplication%2Flogin.php%3C%2Fb%3E%20on%20line%20%3Cb%3E5%3C%2Fb%3E%3Cbr%20%2F%3E%0A%3Cbr%20%2F%3E%0A%3Cb%3EWarning%3C%2Fb%3E%3A%20%20file_get_contents(http%3A%2F%2Finput)%3A%20failed%20to%20open%20stream%3A%20php_network_getaddresses%3A%20getaddrinfo%20failed%3A%20Temporary%20failure%20in%20name%20resolution%20in%20%3Cb%3E%2Fopt%2Flampp%2Fhtdocs%2Fchatapplication%2Flogin.php%3C%2Fb%3E%20on%20line%20%3Cb%3E5%3C%2Fb%3E%3Cbr%20%2F%3E%0A%3Cbr%20%2F%3E%0A%3Cb%3ENotice%3C%2Fb%3E%3A%20%20Trying%20to%20access%20array%20offset%20on%20value%20of%20type%20null%20in%20%3Cb%3E%2Fopt%2Flampp%2Fhtdocs%2Fchatapplication%2Flogin.php%3C%2Fb%3E%20on%20line%20%3Cb%3E10%3C%2Fb%3E%3Cbr%20%2F%3E%0A%3Cbr%20%2F%3E%0A%3Cb%3ENotice%3C%2Fb%3E%3A%20%20Trying%20to%20access%20array%20offset%20on%20value%20of%20type%20null%20in%20%3Cb%3E%2Fopt%2Flampp%2Fhtdocs%2Fchatapplication%2Flogin.php%3C%2Fb%3E%20on%20line%20%3Cb%3E11%3C%2Fb%3E%3Cbr%20%2F%3E%0A&p1=%7B%7D
at angular.js:99
at wc (angular.js:12133)
at angular.js:12226
at r (angular.js:388)
at Bd (angular.js:12225)
at f (angular.js:13165)
at angular.js:18075
at m.$digest (angular.js:19242)
at m.$apply (angular.js:19630)
at k (angular.js:13473) "Possibly unhandled rejection: {}"
(anonymous) @ angular.js:15697
(anonymous) @ angular.js:11956
g @ angular.js:18105
$digest @ angular.js:19242
$apply @ angular.js:19630
k @ angular.js:13473
v @ angular.js:13730
y.onload @ angular.js:13635
load (async)
(anonymous) @ angular.js:13618
s @ angular.js:13418
(anonymous) @ angular.js:13159
(anonymous) @ angular.js:18075
$digest @ angular.js:19242
$apply @ angular.js:19630
(anonymous) @ angular.js:29127
dispatch @ jquery-3.6.0.js:5430
elemData.handle @ jquery-3.6.0.js:5234

this is my controller file
`//chat application module for whole chat application
var chat = angular.module("chatapp", ["ngRoute"]);

//Routing for whole chat application
chat.config(function($routeProvider){
$routeProvider
.when('/', {
templateUrl: 'indextemplate.html',
controller: 'registerController'
})
.when('/login', {
templateUrl: 'logintemplate.html',
controller: 'loginController'
})
.when('/chats', {
templateUrl: 'chattemplate.html',
controller: 'chatController'
})
.otherwise({
redirectTo: '/'
})
});
chat.service("Auth", function(){
var username;

this.setName = function(name){
    username = name;
};
this.getName = function(){
    return username;
};

})
//controls and validates the register form
chat.controller("registerController", function($scope, $http, $location){
$scope.Register = function(){
if($scope.Name == null || $scope.Name == "" && $scope.Email == null || $scope.Email == "" && $scope.DOB == null || $scope.DOB == "" && $scope.Password == null || $scope.Password == "" && $scope.ConfirmPassword == null || $scope.ConfirmPassword == "" && $scope.Image == null || $scope.Image == ""){
//shows error when any one of the field is not filled in register form
$scope.error = "please fill all the fields";
} else if ($scope.Password != $scope.ConfirmPassword){
//shows error when the password and confirm ppassword dows not match in register form
$scope.passerr = "passwords does not match";
} else {
//inserts into user_register when all the fields are filled and validates
$http.post("insert.php", {
'Name': $scope.Name,
'Email': $scope.Email,
'DOB': $scope.DOB,
'Password': $scope.Password,
'ConfirmPassword': $scope.ConfirmPassword,
'Image': $scope.Image
}).then(function(data){
alert("registered Successfully");
$location.url("/login");
},function(){
alert("data not sent")
})
}
}
});
//controls and validates the login form
chat.controller("loginController", function($scope, $http, $location, Auth){
$scope.Login = function(){
//shows error when any one of the field is not filled in login form
if($scope.Email == null || $scope.Email == "" && $scope.Password == null || $scope.Password == ""){
$scope.loginerror = "please fill all the fields";
} else {
//saves the entered data in the variable
var Email = $scope.Email;
var Password = $scope.Password;
var data = {
'Email': $scope.Email,
'Password': $scope.Password
}
$http.post("login.php", $.param(data),{
headers:{
'Content-Type': 'application/x-www-form-urlencoded'
}
}).then(function(data){
alert("Data Sent");
},function(){
alert("data not sent");
})
//gets the data from the login php script
$http.get("login.php")
.then(function(response){
$scope.names = response.data;
console.log(response.data);
//checks whether the entered data matches with the data in database
if (response.data.Email != Email){
Auth.setName(response.data.Email);
$scope.Emailerr = "Email does not match with our database";
} else if (response.data.Password != Password){
$scope.Passworderr = "Password does not match with our database";
} else {
$scope.success = "successfully loggedin";
$location.url("/chats");//redirects to chats when the user is authenticated user
}

        })
    }
}

});
//controls the chat page
chat.controller("chatController", function($scope, Auth){
$scope.name = Auth.getName();
});'

my php file
`<?php
session_start();
header('Access-Control-Allow-Origin: *');
header('Content-Type: application/json; charset=utf-8');
$json = file_get_contents("http://input");
$data = json_decode($json);
echo $data;
$response = array();
$link = mysqli_connect("localhost", "root", "", "chatapp");
$Email = mysqli_real_escape_string($link, $data['Email']);
$Password = mysqli_real_escape_string($link, $data['Password']);
$Sql = "SELECT * FROM user_register WHERE Email = '$Email' AND Password = '$Password'";
$result = mysqli_query($link, $Sql);
if(mysqli_num_rows($result) > 0){
while($row = mysqli_fetch_assoc($result)){
$response[] = $row;
}
json_encode($response);
}

?>`