Php 将JSON数据插入Angularjs中的数据库

Php 将JSON数据插入Angularjs中的数据库,php,mysql,angularjs,json,Php,Mysql,Angularjs,Json,我正在处理一个表单,它有一个动态生成的字段。我的问题是我不能从这些生成的字段中插入数据。我试过这条线,但它对我不起作用 我尝试在传输到PHP时填充数据,但没有成功 DB连接 <?php class DbConfig { private $_host = 'localhost'; private $_username = 'root'; private $_password = ''; private $_database = 'machines';

我正在处理一个表单,它有一个动态生成的字段。我的问题是我不能从这些生成的字段中插入数据。我试过这条线,但它对我不起作用

我尝试在传输到PHP时填充数据,但没有成功

DB连接

<?php
class DbConfig 
{   
    private $_host = 'localhost';
    private $_username = 'root';
    private $_password = '';
    private $_database = 'machines';

    protected $connection;

    public function __construct()
    {
        if (!isset($this->connection)) {

            $this->connection = new mysqli($this->_host, $this->_username, $this->_password, $this->_database);

            if (!$this->connection) {
                echo 'Cannot connect to database server';
                exit;
            }           
        }   

        return $this->connection;
    }
}
?>
控制器

$scope.register=function(){   
    $http.post("http://localhost/clickermag/controller/register.php", {
    'company':$scope.company,
    'email':$scope.email,
    'phone':$scope.phone,
    'position':$scope.position,
    'firstName':$scope.firstName,
    'lastName':$scope.lastName,
    'presses':$scope.columns
  })

    .then(function(response){
                    console.log("Data Inserted Successfully");
                },function(error){
                    alert("Sorry! Data Couldn't be inserted!");
                    console.error(error);

                });
        }
PHP文件

<?php
$data = json_decode(file_get_contents("php://input"));

//including the database connection file
include_once("../classes/Crud.php");

$crud = new Crud();


$company = $data->company;
$email = $data->email;
$phone = $data->phone;
$position = $data->position;
$firstName = $data->firstName;
$lastName = $data->lastName;
$ownedPress = $data->presses;

        //insert data to database   
$result = $crud->execute("INSERT INTO users(company, email, phone, position, first_name, last_name) VALUES('$company','$email','$phone','$password','$position','$firstName','$lastName')");

$last_id = $crud->user_id;

foreach($data as $item) {
       $pressesQuery = $crud->execute("INSERT INTO owned_presses(user_id, brand, tonnage, table_size, press_type) VALUES ('$last_id','$item[brand]','$item[tonnage]','$item[tableSize]','$item[pressType]')");
     }

?>
首先要做的事

现在,

为什么要循环使用
$data
,难道不应该循环使用
$ownedPress

而且,我不确定如何实现
Crud.php
,但我假设它是:

$last_id = $result->user_id;
foreach($data as $item) {
$last_id = $result->user_id;