数据未插入数据库
</div>
<div id="osx-modal-content" ng-app="newtask" ng-controller="taskcontroller">
<div id="osx-modal-title">Adding a new task</div>
<div class="close"><a href="#" class="simplemodal-close">x</a></div>
<div id="osx-modal-data">
<form method="POST" action="">
Task Tittle: <input type="text" name="name" ng-model="taskname" >
<input class="add-input" name="description" placeholder="I need to..." type="text" ng-model="description" ng-model-instant />
Due date : <input id="date" type="text" name="date" size="15" ng-model="date"/>
Priority : <select id="priority" name="priority" ng-model="priority">
<option name="high">High</option>
<option name="medium">Medium</option>
<option name="low">low</option>
</select>
Date created: <input id="datec" type="text" name="datec" size="15"/>
<button type="submit" class="simplemodal-close" ng-click="insertdata()"><h5>Add</h5></button>
</form>
</div>
</div>
这是insertdata()的angularjs函数:
var app=angular.module('newtask',[]);
app.controller('taskcontroller',function($scope,$http){
$scope.insertdata=function(){
$http.post("insert.php",{'taskname':$scope.taskname,'description':$scope.description,'date':$scope.date,'priority':$scope.priority,'datec':$scope.datec})
.success(function (data, status, headers, config) {
console.log("New Task Inserted")
})
}
});
这里是用于解除json和用于将数据插入数据库的查询的php文件
$data = json_decode(file_get_contents("php://input"));
$taskname = mysql_real_escape_string($data->taskname);
$description = mysql_real_escape_string($data->description);
$date = mysql_real_escape_string($data->date);
$priority = mysql_real_escape_string($data->priority);
$datec = mysql_real_escape_string($data->datec);
mysql_connect("localhost","root","");
mysql_select_db("todo");
mysql_query("INSERT INTO tasks(`name` , `datecreated` , `duedate` , `priority` , `description`)
VALUES('".$taskname."' , '".$datec."' , '".$date."' , '".$priority."' , '".$description."')");
答案 0 :(得分:0)
在查询后使用 die(mysql_error()); ,而不是找到解决方案
mysql_query("INSERT INTO tasks(`name` , `datecreated` , `duedate` ,
`priority` , `description`)
VALUES('".$taskname."' , '".$datec."' , '".$date."' ,
'".$priority."' , '".$description."')") or die(mysql_error());