1

I need one help for inserting array of data into database using PHP,MySQL and angular.js.Let me to explain my code.Suppose i have the below set of data which will insert into database.

$scope.listOfData=[
    0:{'name':raj,'email':[email protected],'rollno':11,'subject`:abc},
    1:{'name':raja,'email':[email protected],'rollno':13,'subject`:ab},
    2:{'name':raja1,'email':[email protected],'rollno':113,'subject`:anb},
    ....................................................................
    .....................................................................

    20:{'name':raja1,'email':[email protected],'rollno':113,'subject`:anb},
];

I have 20 numbers of data in one object and i have only 4 field in database (i.e-name,email,rollno,subject).When user will click on submit button these 20 nos of data will insert in DB in 20 rows.Here i need how it can be done in php. In this below code i am declaring the submit function.

$scope.addData=function(){
   $http({
        method:'POST',
        url: "php/timetable/addTimeTable.php",
        data:$scope.listOfTimeData,
        headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
    }).then(function successCallback(response){
        //Success callback
    },function errorCallback(response) {
        //Error callback
    });
};

Here i need how i will pass the all data to php file and insert all data in Mysql (Lets say table name-db_user) DB at a time in a loop.Please help me.

3
  • php.net/manual/en/function.serialize.php Commented Oct 16, 2015 at 5:46
  • $scope.listOfData is invalid. Commented Oct 16, 2015 at 5:55
  • @SarjanDesai : its ok i was just trying to display the console output of listOfData.But my requirement is something else. Commented Oct 16, 2015 at 6:01

1 Answer 1

0

Format of your $scope.listOfData is invalid. it should be like

$scope.listOfData=[
{'name':raj,'email':[email protected],'rollno':11,'subject`:abc},
{'name':raja,'email':[email protected],'rollno':13,'subject`:ab},
{'name':raja1,'email':[email protected],'rollno':113,'subject`:anb},
....................................................................
.....................................................................

{'name':raja1,'email':[email protected],'rollno':113,'subject`:anb},
];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.