您插入数据的脚本错误。将其替换为以下内容
$http.post("server/insert.php",{'fstname': $scope.newFriend.fname, 'lstname': $scope.newFriend.lname}) .success(function(data, status, headers, config){ console.log("inserted Successfully"); });并按如下方式更改php。
$data = json_depre(file_get_contents("php://input"));$fstname = mysql_real_escape_string($data->fstname);$lstname = mysql_real_escape_string($data->lstname);mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("angularjs") or die(mysql_error()); mysql_query("INSERT INTO friends (fname,lname) VALUES ('$fstname', '$lstname')"); Print "Your information has been successfully added to the database.";当我尝试使用您的代码时,这对我有用。



