createAccount.php
 $server = 'localhost';
$username ="xxx";
$passwd ='xxx';
$Dbase = 'xxx';
$db = mysqli_connect($server,$username,$passwd) or die("Could not connect database");
        mysqli_select_db($db, $Dbase) or die("Could not select database");
//http://stackoverflow.com/questions/15485354/angular-http-post-to-php-and-undefined
$postdata = file_get_contents("php://input");
if (isset($postdata)) {
    $request = json_decode($postdata);
    $firstName = $request->firstName;
    $lastName = $request->lastName;
    $email = $request->email;
    $password = $request->password;
    if ($firstName != "") {
        mysqli_query($db, "INSERT INTO users(`firstName`, `lastName`, `email`, 
`password`)VALUES('".$firstName."','".$lastName."','".$email."','".$password."')");
        echo "firstName: " . $firstName;
        echo "lastName: " . $lastName;
        echo "email: " . $email;
        echo "password: " . $password;
    }
    else {
        echo "Empty username parameter!";
    }
}
else {
    echo "Not called properly with username parameter!";
}
 
 
controller.js
angular.module('starter.controllers', []).controller('registrationCtrl',  
function ($scope, $http) {
        $scope.data = {};
        $scope.submit = function(){
            var link = 'http://proittechnology.com/dev/stylr/createAccount.php';
            $http.post(link, { firstName: $scope.data.firstName, 
lastName: $scope.data.lastName, email: $scope.data.email, password: $scope.data.password })
.then(function (res) {
                $scope.response = res.data;
                alert('Your account has been created successfully');
            });
        };
    })
 
 
home.html
<ion-view view-title="Registration">
        <ion-content padding="true">
            <form ng-submit="submit()">
                <label class="item item-input item-stacked-label">
                    <span class="input-label">First Name</span>
                    <input type="text" name="firstName" placeholder="First Name" 
 ng-model="data.firstName">
                </label>
                <label class="item item-input item-stacked-label">
                    <span class="input-label">Last Name</span>
                    <input type="text" name="lastName" placeholder="Last Name"  
ng-model="data.lastName">
                </label>
                <label class="item item-input item-stacked-label">
                    <span class="input-label">Email</span>
                    <input type="text" id="email" name="email" ng-keyup="checkemail()" 
 placeholder="Email" ng-model="data.email">
                    <span id="email_status"></span>
                </label>
                <label class="item item-input item-stacked-label">
                    <span class="input-label">Password</span>
                    <input type="text" name="password" placeholder="Password" 
 ng-model="data.password">
                </label>
                <input class="button button-block button-positive" type="submit" 
 name="submit" value="Create Account">        
            </form>
            <div class="row">
                <div class="col col-50">
                </div>
                <div class="col col-50 text-right">
                    <a href="#/login" class="button button-outline button-positive">Login</a>
                </div>
            </div>
        </ion-content>
</ion-view>
 
MongoDB
ReplyDeleteHTML
Javascript
NodeJS