Saving data from form to database using AngularJS and php

I am new to angular.
I created a modal window for user history and after that show it in the body:

Html

 <button class="btn btn-primary new-story" ng-click="showPopup()">New Story</button>


            <div class="wroteStory img-rounded" ng-repeat="story in sentCompose">

                <h1 class="s-label"><i><label for="subject">Subject :</label></i></h1>
                <h5>{{story.subject}}</h5>


                <h1 class="s-label"><i><label for="body">Full Story :</label></i></h1>
                <h6>{{story.body}}</h6>
                <button class="btn btn-danger" ng-click="remove($index)"> Delete </button>
                <hr/>
            </div>

      

Js

app.controller('aboutController', function($scope,ngProgress) {


$scope.popupVisible = false;
$scope.showPopup = function(){
    $scope.popupVisible = true;
    $scope.composeStory = {};
}
$scope.closePopup = function(){
    $scope.popupVisible = false;
}


$scope.composeStory = {};
$scope.sentCompose = [];

$scope.sendStory = function() {
   $scope.sentCompose.push($scope.composeStory);
    $scope.popupVisible = false;


    $http.post("insert.php", data).success(function(data, status, headers, config){

    });

};

      

I want to save data from this form to the database? thanks in advance

+4


source to share


2 answers


Having given you limited information, I will try to help you with this. When you ask questions, please show what kind of output you get, what your debug says. Others will benefit from understanding your problem and suggesting a solution to you. Here are my suggestions

1) I was unable to see the scope of your data variable $http.post("insert.php", **data**)

to make sure there is serialized data in it.

2) Check in firebug if your request is being sent or not. If you see a request, see what response you are getting



3) Since you have a success handler, there is always an error handler for any Ajax call, this is the best method that saves you time when debugging.

My suggestions are based on the assumption that yours is insert.php

checked for correct data insertion. If not, then you should follow what John Conde said

0


source


first you have to create a db in mysql and create a table for that.
then you should be able to connect them to php like this:



    $host = "localhost";
$user = "angular";
$pass = "angular";
$database = "angular";
$con = mysql_connect($host,$user,$pass);
if (!$con) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_select_db($database,$con);

      

0


source







All Articles