Hi everyone, i'm creating a little application which i have to complete as 
test work, in this application i can create users, see list with all users, 
delete users and update users.
I've created form with inputs and ng-click directive on the button, and 
i've created database with table `info` with iformatioan about all users, i 
completed part of the work where i have to create users i did it so:

This is my controller:
app.controller('MainController', ['$scope', '$http', function($scope, 
$http) {
 $http.get('server.php')
.success(function(data) {
$scope.users = data
})
.error(function(err) {
console.log(err);
});

$scope.addUser = function() {
$http.post('server.php', {'name':$scope.name, 'email':$scope.email, 
'telephone':$scope.telephone, 'city':$scope.city,
'address':$scope.address, 'state':$scope.state, 'zip':$scope.zip})
.success(function(data) {
console.log(data);
})
.error(function(err) {
console.log(err);
});
}
}]);

and this is my server:
<?php
define("DB_HOST", "localhost");
define("DB_LOGIN", "root");
define("DB_PASSWORD", "000000");
define("DB_NAME", "users");


mysql_connect(DB_HOST, DB_LOGIN, DB_PASSWORD);
mysql_select_db(DB_NAME);

if ($_SERVER['REQUEST_METHOD'] == "POST") {
  $data = json_decode(file_get_contents("php://input"));
  $name = mysql_real_escape_string($data->name);
  $email = mysql_real_escape_string($data->email);
  $telephone = mysql_real_escape_string($data->telephone);
  $city = mysql_real_escape_string($data->city);
  $address = mysql_real_escape_string($data->address);
  $state = mysql_real_escape_string($data->state);
  $zip = mysql_real_escape_string($data->zip);



  $sql = "INSERT INTO info(`name`, `email`, `telephone`, `city`, `address`, 
`state`, `zip`)VALUES(
   '".$name."', '".$email."', '".$telephone."', '".$city."', 
'".$address."', '".$state."', '".$zip."')";
  mysql_query($sql) or die(mysql_error());
} elseif ($_SERVER['REQUEST_METHOD'] == 'GET') {
    $sql = 'SELECT * FROM `info` ';
    $result = mysql_query($sql) or die(mysql_error());
    return $result;
    mysql_close();
}

?>
i'm trying to get all users information and display it somewhere near with 
my form, but it is unclear why no information is coming(

here is my HTML
<!doctype html>
<html lang="en" ng-app="mainApp">
<head>
  <meta charset="utf-8">
  <title>TesWork</title>
  <script 
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js";></script>
  <script 
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-route.min.js";></script>
  <link rel="stylesheet" href="css/app.css">
  <link rel="stylesheet" href="css/bootstrap.css">
</head>




<body ng-controller="MainController">

  <div ng-repeat="user in users">
    {{user.name}}
  </div>

<div class="container">
  <form>
    Name <input type="text" ng-model="name"></br>
    Email <input type="text" ng-model="email"></br>
    Telephone <input type="text" ng-model="telephone"></br>
    City <input type="text" ng-model="city"></br>
    Address <input type="text" ng-model="address"></br>
    State <input type="text" ng-model="state"></br>
    ZIP <input type="text" ng-model="zip"></br>
    <input type="button" value="submit" ng-click="addUser()">
  </form>
</div>


<!-- Angular.js core JavaScript
================================================== -->

<script src="js/app.js"></script>
<script src="js/controller.js"></script>
</body>
</html>

Can somebody give me hint what goes wrong, maybe it's some troubles with my 
query?
I will very appreciate if somebody explain me, thanks)


-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to angular+unsubscr...@googlegroups.com.
To post to this group, send email to angular@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to