我使用Angular Js,PHP和mySql创建了Web应用程序。应用程序中有很多插入表单。
所有插入数据库的工作都非常好。
我的问题是:我无法使用update mySql查询更新我的表单。
我认为问题与形式有关,但我无法弄清楚实际问题是什么。
请检查错误的位置
这是我的Html标记: -
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" ng-controller="dhmsEditSection">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body" ng-repeat="u in details.requirement_detail track by $index">
<div class="">
<div class="page-content">
<form class="form-horizontal ng-pristine ng-valid">
<fieldset>
<legend>New Project Requirement</legend>
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right">Requirement No.</label>
<div class="col-sm-7">
<span class="block input-icon input-icon-right">
<input type="text" class="form-control" disabled ng-model="reqID" value="{{u.id}}" placeholder="Req. No. {{u.id}}">
</span>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right">Client Name</label>
<div class="col-sm-7">
<span class="block input-icon input-icon-right">
<input type="text" class="form-control" value="{{u.rClientName}}" ng-model="{{u.rClientName}}" ng-model="rClientName" >
</span>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right">Contact No.</label>
<div class="col-sm-7">
<span class="block input-icon input-icon-right">
<input type="text" class="form-control" name="rContactNumber" value="{{u.rContactNumber}}" ng-model="{{u.rContactNumber}}" >
</span>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right">Company Name</label>
<div class="col-sm-7">
<span class="block input-icon input-icon-right">
<input type="text" class="form-control" value="{{u.rCompanyName}}" ng-model="rClientName">
</span>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right">Email Address</label>
<div class="col-sm-7">
<span class="block input-icon input-icon-right">
<input type="text" class="form-control" ng-model="rEmail" value="{{u.rEmail}}" >
</span>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right">Requirement Information</label>
<div class="col-sm-7">
<span class="block input-icon input-icon-right">
<textarea class="form-control" ng-model="rRequirement" >{{u.rRequirement}}</textarea>
</span>
</div>
</div>
</fieldset>
</form>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" ng-click="updatedata()">Save changes</button>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
<!-- /.modal -->
控制器:
dhmsApp.controller('dhmsEditSection',function($scope,$http){
$scope.updatedata=function(){
$http.post("include/editSectionBg.php",{'rClientName':$scope.rClientName,'rContactNumber':$scope.rContactNumber,'rCompanyName':$scope.rCompanyName,'rEmail':$scope.rEmail,'rRequirement':$scope.rRequirement})
.success(function(data,status,headers,config){
alert("Data inserted successfully");
});
}
});
editSectionBg.php
<?php
$data = json_decode(file_get_contents("php://input"));
$reqID = $data->reqID;
$rClientName = $data->rClientName; // mysql_real_escape_string Escapes special characters in a string for use in an SQL statement
$rContactNumber = $data->rContactNumber;
$rCompanyName = $data->rCompanyName;
$rEmail = $data->rEmail;
$rRequirement = $data->rRequirement;
// syntax for mysql connect == "mysql_connect(host,username,password);"
include("connection_string.php");
include("connectionStringFetch.php");
mysqli_query($db, "update dhms_requirement set `rClientName`='".$rClientName."', `rContactNumber`='".$rContactNumber."', `rCompanyName`='".$rCompanyName."', `rEmail`='".$rEmail."', `rRequirement`='".$rRequirement."' where id='".$reqID."'");
?>
答案 0 :(得分:0)
我认为您缺少在帖子数据中添加reqID
$reqID = $data->reqID;