Я использую форму angularjs с базой данных mysql для хранения и извлечения данных с помощью mysql, но им не удается выполнить операции crud с угловыми. im new to angularjs, пожалуйста, помогите мне с тем же. ниже мой код для формы.Как вставить записи с angularjs php и mysql?
<form >
<div class="control-group">
<label class="control-label" >Referal code:</label>
<div class="controls">
<input required type='text' class='span2' ng-model='tempUserData.referal_code'>
</div>
</div>
<div class="control-group">
<label class="control-label">Name:</label>
<div class="controls">
<input required type="text" ng-model="tempUserData.emp_name" class="span2">
</div>
</div>
<div class="control-group">
<label class="control-label">Date:</label>
<div class="controls input-group">
<datepicker>
<input required type="text" ng-model="tempUserData.date" class="span2">
</datepicker>
</div>
</div>
<div class="control-group">
<label class="control-label" >Date Of Joining:</label>
<div class="controls">
<datepicker>
<input required type="text" ng-model="tempUserData.dateofjoining" class="span2">
</datepicker>
</div>
</div>
<div class="control-group">
<label class="control-label" >Admin Name:</label>
<div class="controls">
<input required type="text" ng-model="tempUserData.admin" class="span2">
</div>
</div>
<div class="control-group">
<label class="control-label" >Address:</label>
<div class="controls">
<input required type="text" ng-model="tempUserData.address" class="span2">
</div>
</div>
<div class="control-group ">
<label class="control-label">Company Name:</label>
<div class="controls">
<select ng-model="tempUserData.company_name" class="span2">
<option ng-repeat="x in names" value="{{x.company_name}}">{{x.company_name}}</option>
</select>
</div>
</div>
<div class="control-group">
<label class="control-label" >Title:</label>
<div class="controls">
<input required type="text" ng-model="tempUserData.title" class="span2">
</div>
</div>
<button class="btn btn-primary" type="submit" ng-hide="tempUserData.id" ng-click="addUser()"> Add Letter</button>
Скрипт для этой формы:
<script>
var app = angular.module('myApp', ['720kb.datepicker']);
app.controller('myCtrl', function($scope, $http)
{
$http.get("http://www.adhr.adnacgroup.com/ADHRM/companyJson.php")
.then(function(response)
{$scope.names = $scope.names = response.data.service;});
$scope.addTask = function (task) {
$http.post("addTask.php?task="+task).success(function(data){
getTask();
$scope.tempUserData.referal_code= "";
$scope.tempUserData.emp_name = "";
$scope.tempUserData.date = "";
$scope.tempUserData.dateofjoining = "";
$scope.tempUserData.admin = "";
$scope.tempUserData.address = "";
$scope.tempUserData.company_name = "";
$scope.tempUserData.title = "";
});
};
});
</script>
Вставка запроса:
if(isset($_GET['task'])){
$task1 = $_GET['task'];
$task2 = $_GET['task'];
$task3 = $_GET['task'];
$task4 = $_GET['task'];
$task5 = $_GET['task'];
$task6 = $_GET['task'];
$task7 = $_GET['task'];
$task8 = $_GET['task'];
$query9=mysql_query("INSERT INTO `offer_letter`(`org_id`, `com_id`, `id`, `admin_name`, `address`, `offer_referal_code`, `com_name`, `title`, `date`, `dateofjoining`) VALUES ('".$_SESSION[org_id]."','".$task1."','".$task2."','".$task3."','".$task4."','".$task5."','".$task6."','".$task7."','".$task8."','".$task9."')");
$result = mysql_affected_rows($query);
echo $json_response = json_encode($result);
}
Я не могу видеть, где вы звоните AddTask() в коде? – Shubhranshu
@ Вставить запрос в Shubhranshu - это мой addTask.php –