drn1008 2018-12-06 09:56
浏览 47

Angular架构表单 - 使用PHP和Mysql插入数据

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

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 数学建模,尽量用matlab回答,论文格式
    • ¥15 昨天挂载了一下u盘,然后拔了
    • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
    • ¥20 易康econgnition精度验证
    • ¥15 msix packaging tool打包问题
    • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
    • ¥15 python的qt5界面
    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能