javascript - 使用 AngularJS 和 php 将数据从表单保存到数据库

标签 javascript php database angularjs

我是 angular 的新手。
我创建了一个模态窗口供用户分享故事,然后在正文中显示:

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){

    });

};

我想将此表单中的数据保存到数据库中? 提前致谢

最佳答案

首先,您应该能够在 mysql 中创建一个数据库并为其创建一个表。
那么您应该能够像这样将它们与 php 连接:

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

关于javascript - 使用 AngularJS 和 php 将数据从表单保存到数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26207778/

相关文章:

javascript - Orchestrate.js 同时触发 'promise.fail' 和 'promise.then'

javascript - 如何从 TAB 导航中跳过表单元素?

javascript - 控制台警告 : component lists rendered with v-for should have explicit keys

PHP zend字节码引用?

sql - JOINS 和 SUBQUERIES 之间有什么区别?我们可以用连接做的任何事情也可以用子查询来做,反之亦然吗?

javascript - 如何在 JavaScript/jQuery 中缩小 HTML block ?

php - 带有 ajax 和 php 的 javascript 函数无法正常工作

php - Laravel 社交名流 : InvalidStateException

javascript - 使用动态字段将数据插入数据库

mysql - 使用hibernate在查询MySQL数据库中排序