AngularJS Question

Getting blank value in database using angular js

I have a contact form containing 3-4 fields. I am just trying to send only first field into database using Angular-js. But i am getting blank value in database.
Can you guys please check where is actually i am going wrong ?


<div ng-app="contactApp" ng-controller="contactController">
<div class="contact-grids">
<div class="col-md-12 contact-para">
<form name="userForm" ng-submit="submitForm()" novalidate>
<div class="grid-contact">
<div class="col-md-6 contact-grid" ng-class="{'has-error':userForm.firstName.$invalid && !userForm.firstName.$pristine}">

<p>First Name</p>
<input type="text" name="firstName" ng-model="user.firstName" required>
<p ng-show="userForm.firstName.$invalid && !userForm.firstName.$pristine" class="help-block">You name is required.</p>

<div class="send">
<input class="btn btn-danger" type="submit" value="Send" ng-disabled="userForm.$invalid">

var myApp = angular.module('contactApp',[]);

$scope.submitForm = function()

$scope.firstName = null;





$data = json_decode(file_get_contents("php://input"));
if(count($data) > 0)

$first_name = mysqli_real_escape_string($conn, isset($data>firstName));
$query = "INSERT INTO contactform(firstName) VALUES ('$first_name')";
if(mysqli_query($conn, $query))
echo "Data Inserted...";
echo 'Error';

Answer Source

You need to change $scope.firstName in the function to $scope.userForm.firstName. As for now, $scope has no member named firstName, that's why it's empty in your function.

EDIT: Actually, you need $scope.user.firstName, $scope.userForm.firstName is angular model object and it not what is needed in this context.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download