How do you compare values from AngularJS form data and MySQL database (PHP)? -


i can display entire table of database on partial view, want filter , compare 1 of them output form. how display entire table.

server/fetch.php

<?php     $connect = mysqli_connect("localhost", "root", "ralph2012", "mipadsignup");   $result = mysqli_query($connect, "select * tbl_codes");    $data = array();    while ($row = mysqli_fetch_array($result)) {     $data[] = $row;   }    print json_encode($data); ?> 

app.js (where controller is)

http.get("server/fetch.php").success(function(response){   scope.response = response; }).error(function() {   scope.response = "error in fetching data"; }); 

registration.php

<ul ng-repeat="codes in response">   <li>{{codes.id}} {{codes.code}} {{codes.branch}} {{ formdata.branches.alias }}</li> </ul> 

the formdata.branches.alias taken output produced 1 of form elements. want value compared codes.branch, database. not want list everything. want portion of codes.branch run check within similar row values.

after comparing two, want run again through columns , check if of them available. if are, randomly select 1 of values inserted other table in database.

[update]: requested, form

<div class="wrapper">     <div class="form-group">         <input class="form-control" ng-class="{'has-error': $submitted && signup.name.$invalid}" type="text" name="name" ng-model="formdata.name" required minlength="2" placeholder="full name">     </div>    <div class="form-group">     <input class="form-control" ng-class="{'has-error': $submitted && signup.igname.$invalid}" type="text" name="igname" ng-model="formdata.igname" minlength="2" placeholder="instagram name (optional)">   </div>      <div class="form-group">     <input type="email" class="form-control" name="email" ng-class="{'has-error': $submitted && signup.email.$invalid}" ng-model="formdata.email" ng-pattern="/[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/" placeholder="e-mail address" required>   </div>    <div class="form-group">     <input type="number" name="mobile" ng-class="{'has-error': $submitted && signup.mobile.$invalid}" ng-model="formdata.mobile" required class="form-control" minlength="11" maxlength="11" placeholder="mobile number">   </div>    <div class="form-group form-inline">     <span class="nullable">       <select id="regions" class="form-control" ng-model="formdata.location" required ng-options="rg rg.type rg in region">         <option value="">choose location</option>       </select>     </span>     <span class="nullable">       <select id="branches" class="form-control" ng-model="formdata.branches" required ng-options="c c[formdata.location.displayname] c in formdata.location.data | orderby:'branch'">         <option value="">choose branch</option>       </select>        </span>   </div>   <div class="form-group row">     <button type="submit" class="submit btn">submit</button>   </div> </div> 

i run checks here (registration.php):

<form id="signup-form" name="signup" ng-submit="processform(signup.$valid)" novalidate>   <!-- our nested state views injected here -->   <div id="form-views" ui-view></div> </form>  <pre style="margin-top: 2em;">   <h3 style="margin:0 0 0 12px; padding: 0; line-height: 0;">form validation test</h3>   <span>if displays, it's valid.</span>   {{ formdata.name }}   {{ formdata.igname }}   {{ formdata.email }}   {{ formdata.mobile }}   {{ formdata.location.type }}   {{ formdata.branches.branch }}   {{ formdata.branches.alias }} </pre> 

i want assign 1 codes.code registered user , mark taken column 1 code can never reused other registered users, until rans out , gives message no more codes available registration.

this insert inputs other table in database.

http.post("server/insert.php",{'code': $code, 'fullname': scope.formdata.name, 'instagram': scope.formdata.igname, 'email': scope.formdata.email, 'mobile': scope.formdata.mobile, 'location': scope.formdata.location.type, 'branch': scope.formdata.branches.branch}).success(function(data, status, headers, config){       console.log("inserted successfully");     }); 

and server/insert.php

$postdata = file_get_contents("php://input"); $request = json_decode($postdata); @$code = $request->code; @$fullname = $request->fullname; @$instagram = $request->instagram; @$email = $request->email; @$mobile = $request->mobile; @$location = $request->location; @$branch = $request->branch; $date = date('y-m-d h:i:s');  $query = "insert tbl_registration (code,fullname,instagram,email,mobile,location,branch,date_registered) values ('" . $code . "', '" . $fullname . "', '" . $instagram . "', '" . $email . "','" . $mobile . "','" . $location . "','" . $branch . "','" . $date . "')"; 

you can check them against , display them if equal see below code per seeing form. i'm wondering wouldn't suffice needs? add code input in form below:

    <div class="wrapper">     <div class="form-group">         <input class="form-control" ng-class="{'has-error': $submitted && signup.name.$invalid}" type="text" name="name" ng-model="formdata.name" required minlength="2" placeholder="full name">     </div>    <div class="form-group" ng-repeat="codes in response | orderby:random | limitto:1" ng-if="codes.branch == formdata.branches.alias && codes.taken == 0">       <input class="form-control" type="text" name="code" ng-model="formdata.code" ng-value="codes.id">   </ul>    <div class="form-group">     <input class="form-control" ng-class="{'has-error': $submitted && signup.igname.$invalid}" type="text" name="igname" ng-model="formdata.igname" minlength="2" placeholder="instagram name (optional)">   </div>      <div class="form-group">     <input type="email" class="form-control" name="email" ng-class="{'has-error': $submitted && signup.email.$invalid}" ng-model="formdata.email" ng-pattern="/[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/" placeholder="e-mail address" required>   </div>    <div class="form-group">     <input type="number" name="mobile" ng-class="{'has-error': $submitted && signup.mobile.$invalid}" ng-model="formdata.mobile" required class="form-control" minlength="11" maxlength="11" placeholder="mobile number">   </div>    <div class="form-group form-inline">     <span class="nullable">       <select id="regions" class="form-control" ng-model="formdata.location" required ng-options="rg rg.type rg in region">         <option value="">choose location</option>       </select>     </span>     <span class="nullable">       <select id="branches" class="form-control" ng-model="formdata.branches" required ng-options="c c[formdata.location.displayname] c in formdata.location.data | orderby:'branch'">         <option value="">choose branch</option>       </select>        </span>   </div>   <div class="form-group row">     <button type="submit" class="submit btn">submit</button>   </div> </div> 

javascript random order :

$scope.random = function(){     return 0.5 - math.random(); }; 

Comments