I have a code with AngularJS that should receive data in a form in a partial and then return a table with the corresponding results in a database mysql any idea how to fix it
First partial form:
<form>
<div class="row">
<div class="input-field col s12">
<input id="seacrh" autofocus type="text" class="validate" ng-model="searching.name" required>
<label for="search">Search</label>
</div>
</div>
<div class="row">
<div class="col s12">
<button class="waves-effect waves-yel btn btnSearch col s12" ng-click="searchingElement()"><i class="fa fa-search icoSrch"></i></button>
</div>
</div>
</form>
Second partial table:
<tr ng-repeat="element in elements">
<td>{{element.name}}</td>
<td>5</td>
<td><button class="waves-effect waves-light btn blue">Details</button></td>
</tr>
Is that the php code works because the probe by console, but here is:
<?php
$data = json_decode(file_get_contents("php://input"));
$name = $data->name;
$conn = new mysqli("localhost", "user", "pass","DBName");
$sql = "SELECT `elements`.name FROM `elements` WHERE `elements`.name='$name'";
$result = $conn->query($sql);
$array = array();
while($row = $result->fetch_assoc()) {
$array[] = array(
'name' => $row['name']
);}
echo json_encode($array);
?>
app.js here is routes and the controller that I am using:
var app = angular.module('haku_app',['ngRoute'])
app.config(function($routeProvider){
$routeProvider
.when('/',{
templateUrl: "partials/home.html",
controller: 'srchCtrl'
})
.when('/results',{
templateUrl: "partials/results.html",
controller: 'srchCtrl'
})
.otherwise({
redirectTo: '/'
});
});
app.controller('srchCtrl',function($scope, $http){
$scope.serchingElemento= function(){
$http.post("php/search.php",{'name':$scope.searching.name}).success(function(data){
$scope.tiendas= data;
location.href += 'results';
}).error(function(response){
console.log(response);
});
}
});