我正在处理一个包含动态生成字段的表单。我的问题是我无法从这些生成的字段中插入数据。我试过这个帖子How to insert json array into mysql database,但它不适合我。
我试图在转移到PHP时填充数据,但没有运气。
数据库连接
"ATT"
JSON数据
<?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.columns = [
{"id":1,"brand":"robotworx","tonnage":"200","tableSize":"20x50","pressType":"Kiss Cutting"},
{"id":2,"brand":"fanuc","tonnage":"100","tableSize":"30x60","pressType":"Swing Arm"}
];
PHP文件
$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);
});
}
我需要将生成的字段中的数据放到第二个查询中。
答案 0 :(得分:1)
首先,SQL Injection。
现在,
foreach($data as $item) {
为什么要循环浏览$data
,不应该循环浏览$ownedPress
?
而且,我不确定Crud.php
是如何实施的,但我认为它是:
$last_id = $result->user_id;