How to get route parameter data from AngularJS Script to php












0















I checked that my AngularJS Script is working fine. But when i run my php it tells me that index is undefined. I am sure i am not able to transfer data from angular js to php. So please Help me with this thing. I just want to know how can i get data from Angular to php using ($routeParams) so that i can work with it in BackEnd.
Index.html



<!DOCTYPE html>
<html lang="en" ng-app="mod">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>webapp-angular</title>
<script src="scripts/angular.min.js"></script>
<script src="scripts/angular-route.js"></script>
<link rel="stylesheet" href="style.css">
<script src="scripts/script.js"></script>
<base href="/angular/app-route1/"/>
</head>
<body>
<header>
<div class="brand">TDS</div>
<ul>
<li><a href="home">Home</a></li>
<li><a href="courses">Courses</a></li>
<li><a href="employees">Employees</a></li>
</ul>
</header>
<section class="center">
<ng-view></ng-view>
</section>
</body>
</html>


employeeDetails.html



<h1>employee List</h1>
<table>
<thead>
<tr>
<td>id</td>
<td>Name</td>
<td>gender</td>
<td>salary</td>
</tr>
</thead>
<tbody>
<tr>
<td>{{employee.id}}</td>
<td>{{employee.name}}</td>
<td>{{employee.gender}}</td>
<td>{{employee.salary}}</td>
</tr>
</tbody>
</table>
<a href="employees">Back to the list</a>


employee.html



<h1>Employees List</h1>
<ul>
<li ng-repeat="employee in employees">
<a href="employees/{{employee.id}}">{{employee.name}}</a>
</li>
</ul>


new111.php



<?php 
include_once('connect.php');

$id = $_GET['id'];
if($conn && $id){
$output = array();
$query = "select * from employees where id='.$id.'";
$result = mysqli_query($conn,$query);
if(mysqli_num_rows($result)>0){
while($row=mysqli_fetch_assoc($result)){
$output=$row;
echo json_encode($output);
}
}
}
else{
echo "ERROR";
}
?>


Script.js



var myApp=angular
.module("mod",["ngRoute"])
.config(["$routeProvider","$locationProvider",function($routeProvider,$locationProvider){
$routeProvider
.when("/home",{
templateUrl:"home.html",
controller:"homeController"
})
.when("/employees",{
templateUrl:"employees.html",
controller:"employeeController"
})
.when("/courses",{
templateUrl:"courses.html",
controller:"courseController"
})
.when("/employees/:id",{
templateUrl:"employeeDetails.html",
controller:"employeeDetails"
})
.otherwise({
redirectTo:"/home"
})
$locationProvider.html5Mode(true);
}])
.controller("homeController",function($scope){
$scope.message="Home Page";
})
.controller("employeeController",function($scope,$http){
$http.get("php/new11.php")
.then(function(response){
$scope.employees=response.data;
})
})
.controller("courseController",function($scope,$http){
$http.get("php/new1.php")
.then(function(response){
$scope.courses=response.data;
})
})
.controller("employeeDetails",['$scope','$http','$routeParams',function($scope,$http,$routeParams){
console.log($routeParams.id)
$http({
method:'get',
url:"php/new111.php",
params:{id:$routeParams.id}
})
.then(function(response){
$scope.employee=response.data;
})
}])









share|improve this question

























  • You're wide open to SQL injection attacks and should really use Prepared Statements instead of using user data directly in your database queries like that.

    – Magnus Eriksson
    Nov 22 '18 at 9:28











  • Thanks for ur suggestion but i am just learning to implement angularjs. This is not any project but a practice program. Stuck at this point where i have to implement $routeparams with php.

    – Ravi Raina
    Nov 26 '18 at 4:46
















0















I checked that my AngularJS Script is working fine. But when i run my php it tells me that index is undefined. I am sure i am not able to transfer data from angular js to php. So please Help me with this thing. I just want to know how can i get data from Angular to php using ($routeParams) so that i can work with it in BackEnd.
Index.html



<!DOCTYPE html>
<html lang="en" ng-app="mod">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>webapp-angular</title>
<script src="scripts/angular.min.js"></script>
<script src="scripts/angular-route.js"></script>
<link rel="stylesheet" href="style.css">
<script src="scripts/script.js"></script>
<base href="/angular/app-route1/"/>
</head>
<body>
<header>
<div class="brand">TDS</div>
<ul>
<li><a href="home">Home</a></li>
<li><a href="courses">Courses</a></li>
<li><a href="employees">Employees</a></li>
</ul>
</header>
<section class="center">
<ng-view></ng-view>
</section>
</body>
</html>


employeeDetails.html



<h1>employee List</h1>
<table>
<thead>
<tr>
<td>id</td>
<td>Name</td>
<td>gender</td>
<td>salary</td>
</tr>
</thead>
<tbody>
<tr>
<td>{{employee.id}}</td>
<td>{{employee.name}}</td>
<td>{{employee.gender}}</td>
<td>{{employee.salary}}</td>
</tr>
</tbody>
</table>
<a href="employees">Back to the list</a>


employee.html



<h1>Employees List</h1>
<ul>
<li ng-repeat="employee in employees">
<a href="employees/{{employee.id}}">{{employee.name}}</a>
</li>
</ul>


new111.php



<?php 
include_once('connect.php');

$id = $_GET['id'];
if($conn && $id){
$output = array();
$query = "select * from employees where id='.$id.'";
$result = mysqli_query($conn,$query);
if(mysqli_num_rows($result)>0){
while($row=mysqli_fetch_assoc($result)){
$output=$row;
echo json_encode($output);
}
}
}
else{
echo "ERROR";
}
?>


Script.js



var myApp=angular
.module("mod",["ngRoute"])
.config(["$routeProvider","$locationProvider",function($routeProvider,$locationProvider){
$routeProvider
.when("/home",{
templateUrl:"home.html",
controller:"homeController"
})
.when("/employees",{
templateUrl:"employees.html",
controller:"employeeController"
})
.when("/courses",{
templateUrl:"courses.html",
controller:"courseController"
})
.when("/employees/:id",{
templateUrl:"employeeDetails.html",
controller:"employeeDetails"
})
.otherwise({
redirectTo:"/home"
})
$locationProvider.html5Mode(true);
}])
.controller("homeController",function($scope){
$scope.message="Home Page";
})
.controller("employeeController",function($scope,$http){
$http.get("php/new11.php")
.then(function(response){
$scope.employees=response.data;
})
})
.controller("courseController",function($scope,$http){
$http.get("php/new1.php")
.then(function(response){
$scope.courses=response.data;
})
})
.controller("employeeDetails",['$scope','$http','$routeParams',function($scope,$http,$routeParams){
console.log($routeParams.id)
$http({
method:'get',
url:"php/new111.php",
params:{id:$routeParams.id}
})
.then(function(response){
$scope.employee=response.data;
})
}])









share|improve this question

























  • You're wide open to SQL injection attacks and should really use Prepared Statements instead of using user data directly in your database queries like that.

    – Magnus Eriksson
    Nov 22 '18 at 9:28











  • Thanks for ur suggestion but i am just learning to implement angularjs. This is not any project but a practice program. Stuck at this point where i have to implement $routeparams with php.

    – Ravi Raina
    Nov 26 '18 at 4:46














0












0








0








I checked that my AngularJS Script is working fine. But when i run my php it tells me that index is undefined. I am sure i am not able to transfer data from angular js to php. So please Help me with this thing. I just want to know how can i get data from Angular to php using ($routeParams) so that i can work with it in BackEnd.
Index.html



<!DOCTYPE html>
<html lang="en" ng-app="mod">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>webapp-angular</title>
<script src="scripts/angular.min.js"></script>
<script src="scripts/angular-route.js"></script>
<link rel="stylesheet" href="style.css">
<script src="scripts/script.js"></script>
<base href="/angular/app-route1/"/>
</head>
<body>
<header>
<div class="brand">TDS</div>
<ul>
<li><a href="home">Home</a></li>
<li><a href="courses">Courses</a></li>
<li><a href="employees">Employees</a></li>
</ul>
</header>
<section class="center">
<ng-view></ng-view>
</section>
</body>
</html>


employeeDetails.html



<h1>employee List</h1>
<table>
<thead>
<tr>
<td>id</td>
<td>Name</td>
<td>gender</td>
<td>salary</td>
</tr>
</thead>
<tbody>
<tr>
<td>{{employee.id}}</td>
<td>{{employee.name}}</td>
<td>{{employee.gender}}</td>
<td>{{employee.salary}}</td>
</tr>
</tbody>
</table>
<a href="employees">Back to the list</a>


employee.html



<h1>Employees List</h1>
<ul>
<li ng-repeat="employee in employees">
<a href="employees/{{employee.id}}">{{employee.name}}</a>
</li>
</ul>


new111.php



<?php 
include_once('connect.php');

$id = $_GET['id'];
if($conn && $id){
$output = array();
$query = "select * from employees where id='.$id.'";
$result = mysqli_query($conn,$query);
if(mysqli_num_rows($result)>0){
while($row=mysqli_fetch_assoc($result)){
$output=$row;
echo json_encode($output);
}
}
}
else{
echo "ERROR";
}
?>


Script.js



var myApp=angular
.module("mod",["ngRoute"])
.config(["$routeProvider","$locationProvider",function($routeProvider,$locationProvider){
$routeProvider
.when("/home",{
templateUrl:"home.html",
controller:"homeController"
})
.when("/employees",{
templateUrl:"employees.html",
controller:"employeeController"
})
.when("/courses",{
templateUrl:"courses.html",
controller:"courseController"
})
.when("/employees/:id",{
templateUrl:"employeeDetails.html",
controller:"employeeDetails"
})
.otherwise({
redirectTo:"/home"
})
$locationProvider.html5Mode(true);
}])
.controller("homeController",function($scope){
$scope.message="Home Page";
})
.controller("employeeController",function($scope,$http){
$http.get("php/new11.php")
.then(function(response){
$scope.employees=response.data;
})
})
.controller("courseController",function($scope,$http){
$http.get("php/new1.php")
.then(function(response){
$scope.courses=response.data;
})
})
.controller("employeeDetails",['$scope','$http','$routeParams',function($scope,$http,$routeParams){
console.log($routeParams.id)
$http({
method:'get',
url:"php/new111.php",
params:{id:$routeParams.id}
})
.then(function(response){
$scope.employee=response.data;
})
}])









share|improve this question
















I checked that my AngularJS Script is working fine. But when i run my php it tells me that index is undefined. I am sure i am not able to transfer data from angular js to php. So please Help me with this thing. I just want to know how can i get data from Angular to php using ($routeParams) so that i can work with it in BackEnd.
Index.html



<!DOCTYPE html>
<html lang="en" ng-app="mod">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>webapp-angular</title>
<script src="scripts/angular.min.js"></script>
<script src="scripts/angular-route.js"></script>
<link rel="stylesheet" href="style.css">
<script src="scripts/script.js"></script>
<base href="/angular/app-route1/"/>
</head>
<body>
<header>
<div class="brand">TDS</div>
<ul>
<li><a href="home">Home</a></li>
<li><a href="courses">Courses</a></li>
<li><a href="employees">Employees</a></li>
</ul>
</header>
<section class="center">
<ng-view></ng-view>
</section>
</body>
</html>


employeeDetails.html



<h1>employee List</h1>
<table>
<thead>
<tr>
<td>id</td>
<td>Name</td>
<td>gender</td>
<td>salary</td>
</tr>
</thead>
<tbody>
<tr>
<td>{{employee.id}}</td>
<td>{{employee.name}}</td>
<td>{{employee.gender}}</td>
<td>{{employee.salary}}</td>
</tr>
</tbody>
</table>
<a href="employees">Back to the list</a>


employee.html



<h1>Employees List</h1>
<ul>
<li ng-repeat="employee in employees">
<a href="employees/{{employee.id}}">{{employee.name}}</a>
</li>
</ul>


new111.php



<?php 
include_once('connect.php');

$id = $_GET['id'];
if($conn && $id){
$output = array();
$query = "select * from employees where id='.$id.'";
$result = mysqli_query($conn,$query);
if(mysqli_num_rows($result)>0){
while($row=mysqli_fetch_assoc($result)){
$output=$row;
echo json_encode($output);
}
}
}
else{
echo "ERROR";
}
?>


Script.js



var myApp=angular
.module("mod",["ngRoute"])
.config(["$routeProvider","$locationProvider",function($routeProvider,$locationProvider){
$routeProvider
.when("/home",{
templateUrl:"home.html",
controller:"homeController"
})
.when("/employees",{
templateUrl:"employees.html",
controller:"employeeController"
})
.when("/courses",{
templateUrl:"courses.html",
controller:"courseController"
})
.when("/employees/:id",{
templateUrl:"employeeDetails.html",
controller:"employeeDetails"
})
.otherwise({
redirectTo:"/home"
})
$locationProvider.html5Mode(true);
}])
.controller("homeController",function($scope){
$scope.message="Home Page";
})
.controller("employeeController",function($scope,$http){
$http.get("php/new11.php")
.then(function(response){
$scope.employees=response.data;
})
})
.controller("courseController",function($scope,$http){
$http.get("php/new1.php")
.then(function(response){
$scope.courses=response.data;
})
})
.controller("employeeDetails",['$scope','$http','$routeParams',function($scope,$http,$routeParams){
console.log($routeParams.id)
$http({
method:'get',
url:"php/new111.php",
params:{id:$routeParams.id}
})
.then(function(response){
$scope.employee=response.data;
})
}])






php angularjs routeparams






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 9:13









SiddAjmera

15.6k31238




15.6k31238










asked Nov 22 '18 at 9:12









Ravi RainaRavi Raina

11




11













  • You're wide open to SQL injection attacks and should really use Prepared Statements instead of using user data directly in your database queries like that.

    – Magnus Eriksson
    Nov 22 '18 at 9:28











  • Thanks for ur suggestion but i am just learning to implement angularjs. This is not any project but a practice program. Stuck at this point where i have to implement $routeparams with php.

    – Ravi Raina
    Nov 26 '18 at 4:46



















  • You're wide open to SQL injection attacks and should really use Prepared Statements instead of using user data directly in your database queries like that.

    – Magnus Eriksson
    Nov 22 '18 at 9:28











  • Thanks for ur suggestion but i am just learning to implement angularjs. This is not any project but a practice program. Stuck at this point where i have to implement $routeparams with php.

    – Ravi Raina
    Nov 26 '18 at 4:46

















You're wide open to SQL injection attacks and should really use Prepared Statements instead of using user data directly in your database queries like that.

– Magnus Eriksson
Nov 22 '18 at 9:28





You're wide open to SQL injection attacks and should really use Prepared Statements instead of using user data directly in your database queries like that.

– Magnus Eriksson
Nov 22 '18 at 9:28













Thanks for ur suggestion but i am just learning to implement angularjs. This is not any project but a practice program. Stuck at this point where i have to implement $routeparams with php.

– Ravi Raina
Nov 26 '18 at 4:46





Thanks for ur suggestion but i am just learning to implement angularjs. This is not any project but a practice program. Stuck at this point where i have to implement $routeparams with php.

– Ravi Raina
Nov 26 '18 at 4:46












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53427370%2fhow-to-get-route-parameter-data-from-angularjs-script-to-php%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53427370%2fhow-to-get-route-parameter-data-from-angularjs-script-to-php%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

Npm cannot find a required file even through it is in the searched directory