我是 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/