I am trying to insert data from front end to mysql db using angularjs. But it is not geting inserted to the db even though there are no error messages. Foll
Your script for inserting the data is wrong. Replace it with the following
$http.post("server/insert.php",{'fstname': $scope.newFriend.fname, 'lstname': $scope.newFriend.lname})
.success(function(data, status, headers, config){
console.log("inserted Successfully");
});
and also change the php as follows.
$data = json_decode(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.";
This worked for me when I tried with your code.