Javascript 使用angularJS和PHP提交表单

Javascript 使用angularJS和PHP提交表单,javascript,php,angularjs,forms,Javascript,Php,Angularjs,Forms,我用html-bootstrap制作了一个输入表单。我使用AngularJS提交表单(AngularJS对我来说是个新手)。 在大多数情况下似乎效果不错。但现在我有了一个表格,可以节省25%的案例。我找不到数据未保存在其他75%中的原因。我已经调查这件事好几天了,找不到问题所在。 每一个想法或提示都是受欢迎的 我的html表单: <div class="content-wrapper" ng-controller="licenceController"> &

我用html-bootstrap制作了一个输入表单。我使用AngularJS提交表单(AngularJS对我来说是个新手)。 在大多数情况下似乎效果不错。但现在我有了一个表格,可以节省25%的案例。我找不到数据未保存在其他75%中的原因。我已经调查这件事好几天了,找不到问题所在。 每一个想法或提示都是受欢迎的

我的html表单:

<div class="content-wrapper" ng-controller="licenceController">

            <section class="content" >


<!-- LICENCE -->    
                    <div class="row">

                        <div class="col-lg-4 col-md-12" ng-show="licence_view">    
<form name="add_licence" method="post">
        <div class="box box-success">
            <div class="box-header">
                <h3 class="box-title"><?php echo $lang['TTL_LICENCE_CARD']; ?></h3>
            </div><!-- /.box-header -->
            <div class="box-body">
                <input name="licence_id" type="hidden" ng-model="licence_id">
                <div class="form-group">
                  <label><?php echo $lang['LBL_CODE']; ?></label>
                  <input name="code" required="required" ng-disabled="licence_update" type="text" class="form-control" placeholder="..." ng-model="code">
              </div>
              <div class="form-group">
                  <label><?php echo $lang['LBL_LICENCE_DESCRIPTION']; ?></label>
                  <input name="name" required="required" type="text" class="form-control" placeholder="..." ng-model="name">
              </div>
              <div class="form-group">
                  <label><?php echo $lang['LBL_LICENCE_TYPE']; ?></label>
                  <!--input name="type" required="required" type="text" class="form-control" placeholder="..." value="{{a.type_code}}" ng-model="type"-->
                  <select class="form-control" name="repeatlicencetype" id="type" ng-model="type">
                    <option ng-repeat="a in licencetypes" value="{{a.type_code}}">{{a.type_name}}</option>
                </select>
            </div>
            <div class="form-group">
              <label><?php echo $lang['LBL_ROOM_TYPE']; ?></label>
              <input name="roomtype" type="text" class="form-control" placeholder="..." ng-model="roomtype">
          </div>
          <div class="form-group">
              <label><?php echo $lang['LBL_VEHICLE_TYPE']; ?></label>
              <!--input name="vehicletype" required="required" type="text" class="form-control" placeholder="..." ng-model="vehicletype"-->
              <select class="form-control" name="repeatvehicletype" id="vehicletype" ng-model="vehicletype">
                <option ng-repeat="a in vehicletypes" value="{{a.type_no}}">{{a.type_description}}</option>
            </select>
        </div>
        <div class="form-group">
          <label><?php echo $lang['LBL_PRICE']; ?></label>
          <input name="price" type="number" class="form-control" placeholder="..." ng-model="price">
      </div>
      <div class="form-group">
          <label><?php echo $lang['LBL_QUANTITY']; ?></label>
          <input name="quantity" type="number" class="form-control"  placeholder="..." ng-model="quantity">
      </div>
      <div class="form-group">
        <label><?php echo $lang['LBL_COLOR']; ?></label>
        <div  class="input-group my-colorpicker2 colorpicker-element">
            <input name="colorplanning" type="text" class="form-control" ng-model="colorplanning">
            <div class="input-group-addon">
                <i style="background-color: rgb(221, 44, 44);"></i>
            </div>
        </div><!-- /.input group -->
    </div>
    </div><!-- /.box-body -->
    <div class="box-footer">
        <button class="btn btn-success" ng-show='licence_add' ng-click="licence_submit()">
            <span class="glyphicon glyphicon-save"></span> <?php echo $lang['BTN_SUBMIT']; ?>
        </button>
        <button class="btn btn-success" ng-show='licence_update' ng-click="update_licence()">
            <span class="glyphicon glyphicon-save"></span> <?php echo $lang['BTN_SUBMIT_CHANGES']; ?>
        </button>
        <button class="btn btn-info" ng-show='licence_cancel' ng-click="new_licence()">
            <span class="glyphicon glyphicon-share"></span>  <?php echo $lang['BTN_CANCEL']; ?>
        </button>
    </div><!-- /.box-footer -->
    </div><!-- /.box -->
    </form>
$scope.licence_submit = function() {
    $http.post('php/crud_licence.php?action=add_licence', 
    {
        'code'              :   $scope.code,
        'name'              :   $scope.name,
        'licencetype'       :   $scope.type,
        'roomtype'          :   $scope.roomtype,
        'vehicletype'       :   $scope.vehicletype,
        'unitprice'         :   $scope.price,
        'quantity'          :   $scope.quantity,                                                
        'colorplanning'     :   $scope.colorplanning
    }).success(function (data, status, headers, config) {
        getLicences();
    })
    .error(function(data, status, headers, config){
    });
};
我的php代码

function add_licence() {
    $data = json_decode(file_get_contents("php://input"));  
    $code           =   strtoupper ($data->code);
    $name           =   $data->name;
    $licencetype    =   $data->licencetype;
    $roomtype       =   $data->roomtype;
    $vehicletype    =   $data->vehicletype;
    $unitprice      =   $data->unitprice;
    $quantity       =   $data->quantity;
    $colorplanning  =   $data->colorplanning;

    print_r($data);
    $qry = 'INSERT INTO driverlicence (Code,Name,LicenceType,RoomType,VehicleType,UnitPrice,Quantity,ColorPlanning) values ("' . $code . '","' . $name . '","' . $licencetype . '","' . $roomtype . '","' . $vehicletype . '","' . $unitprice . '","' . $quantity . '",' .$colorplanning . ')';

    $qry_res = mysql_query($qry);
    if ($qry_res) {
        $arr = array('msg' => "user Added Successfully!!!", 'error' => '');
        $jsn = json_encode($arr);
        // print_r($jsn);
    } 
    else {
        $arr = array('msg' => "", 'error' => 'Error In inserting record');
        $jsn = json_encode($arr);
        // print_r($jsn);
    }
}

我只是注意到,当我只在表单字段中使用数字时,保存表单是有效的。当我使用varchars时,表单不会提交。

它不工作时有任何错误吗?我没有收到任何错误。您的角度控制器是在哪里定义的?你能把它寄出去吗?还有它绑定到的HTML元素?请不要使用
mysql.*
函数,您实际上没有针对SQL注入的保护。另外,在
.error()
函数中,您可以向控制台输出一些内容,或者您可以查看网络选项卡以查看是否有500个错误。此外,您不应该对所选选项使用
ng repeat
,请使用
ng options