I am going to insert data into a database using angular schema form, but how can I post schemaForm data into PHP, What is wrong in my code, and please let me know how can I learn about Schema form documentation.
app.js
var app = angular.module('myapp', ['schemaForm']);
app.controller('MainCtrl', function($scope,$http) {
$scope.schema = {
"type": "object",
"title": "Comment",
"properties": {
"name": {
"title": "Name",
"type": "string"
}
},
};
$scope.form =
[
"name",
{
"type": "submit",
"style": "btn-info",
"title": "Submit",
"onclick":insert()
}
];
$scope.model = {};
$scope.insert=function()
{
$http.post("insert.php",
{
'name' :$scope.schema[name]
}).then(function(response)
{
console.log("Data Inserted Successfully");
},
function(error)
{
alert("Sorry! Data Couldn't be inserted!");
console.error(error);
});
}
});
This is my PHP Code to do the database connectivity,
<?php
$conn = mysqli_connect("localhost", "root", "demo", "angular");
$info = json_decode(file_get_contents("php://input"));
echo $info->name;
if (count($info) > 0)
{
$name = mysqli_real_escape_string($conn, $info->name);
$query = "INSERT INTO crud(name) VALUES ('$name')";
if (mysqli_query($conn, $query))
{
echo "Data Inserted Successfully...";
}
else {
echo 'Failed';
}
}
?>
Please help