gpt4 book ai didi

mysql - 如何使用 angularjs php 和 mysql 插入记录?

转载 作者:行者123 更新时间:2023-11-29 19:29:40 24 4
gpt4 key购买 nike

我正在使用 AngularJS 表单和 mysql 数据库来使用 mysql 存储和检索数据,但我无法使用 AngularJS 执行增删改查操作。我是 angularjs 的新手,请帮助我。下面是我的表单代码。

<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()">&nbsp;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);
}

最佳答案

要执行 CRUD 操作,您必须像这样以帖子形式发送数据

$http({
url:'addTask.php',
method: 'POST',
params:task
})

在 php 脚本中,您可以获得如下参数:

$task1 = $_POST['task'];

关于mysql - 如何使用 angularjs php 和 mysql 插入记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41887383/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com