Php 数据库插入代码点火器
我在做一个项目,下面是代码,问题是我想在$newMedicament中添加$newrapp数组值(VIS_MATRICULE,RAP_NUM)。 如果(isset($\u POST['add\u relapp'])){ 问题是它说:Php 数据库插入代码点火器,php,database,codeigniter,Php,Database,Codeigniter,我在做一个项目,下面是代码,问题是我想在$newMedicament中添加$newrapp数组值(VIS_MATRICULE,RAP_NUM)。 如果(isset($\u POST['add\u relapp'])){ 问题是它说: A Database Error Occurred Error Number: 1452 Cannot add or update a child row: a foreign key constraint fails (`swissvisite`.`offri
A Database Error Occurred
Error Number: 1452
Cannot add or update a child row: a foreign key constraint fails (`swissvisite`.`offrir`, CONSTRAINT `offrir_ibfk_2` FOREIGN KEY (`VIS_MATRICULE`, `RAP_NUM`) REFERENCES `rapport_visite` (`VIS_MATRICULE`, `RAP_NUM`))
INSERT INTO `offrir` (`VIS_MATRICULE`, `RAP_NUM`, `MED_DEPOTLEGAL`, `OFF_QTE`) VALUES ('a131', '', 'EVILR7', '2')
Filename: C:\wamp\www\code\system\database\DB_driver.php
Line Number: 330
1.看起来您的表swissvisite正在打破RIR_ibfk_2的约束。您知道外键构造依赖于数据完整性。除非您要插入swissvisite的记录的Rapp_visite表中存在(VIS_MATRICULE
,
RAP_NUM),否则无法更新TableA(swissvisite)
2.看起来您正在控制器中执行此操作:这是不正确的:
在构造中加载模型:
public function __construct()
{
parent::__construct();
$this->load->model('mymodel');
}
public function myfunction()
{
$myarray = $_POST['mydata'];
//call your model
$this->mymodel->insert_into_db($myarray);
}
}
最后,请不要将$\u POST数据直接传递到您的查询中,将其绑定到变量并传入。这个问题不清楚。我无法在$newMedicament中添加这两个值,因为它表示数据库错误,这就是问题所在。请编辑您的问题并使其明确clear@user3410718:请拒绝我的编辑。就像你已经做的那样它。好的,谢谢你的编辑。好的,谢谢edward。没有办法同时插入这两个表吗?我会立即进行更改。先将你的记录插入到表report\u visite表中。然后更新你的另一个表。
public function __construct()
{
parent::__construct();
$this->load->model('mymodel');
}
public function myfunction()
{
$myarray = $_POST['mydata'];
//call your model
$this->mymodel->insert_into_db($myarray);
}
}