Form submit with angularJS and PHP

I’ve made an input form in html – bootstrap. And I used AngularJS to submit the form (I’m fairly new to angular).
Seems to work fine in most cases. But now i have a form which saves in 25% of the cases. I cant find the reason why data is not saved in the other 75%. I’ve looked into this for days and cant find the problem.
Every idea or tip is welcome.

My html form:

<form name="add_licence" method="post">
    

<!-- /.box-header -->
{{a.type_name}}
{{a.type_description}}
</div><!-- /.input group --> </div> </div><!-- /.box-body --> <!-- /.box-footer --> </div><!-- /.box --> </form>

Part of my angular script:

$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){
    });
};

My php code

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);
    }
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s