我有 5 个表的数据库
students PK : ID -> anum, first, last
studentinfo PK/FK : ID -> why, student_commenets, finished, aidyear
Times PK/FK : ID -> signintime, counselor_start_time,
additional_time, finish_time
counselor PK/FK : ID -> firstcounselor, secondcounselor, thirdcounselor
Comments PK/FK : ID -> counselorcomments, additional_commenets
我有一个名为 signinpage.php 的页面
在那个页面上,我必须写三个不同的表(学生、学生信息和时间)
我的代码是休闲:
if (empty($errors) === true)
{
include('core/queries/inserts.updates.selects/students.php');
include('core/queries/inserts.updates.selects/studentinfo.php');
include('core/queries/inserts.updates.selects/signintime.php');
$dbh = null;
header('location: signedin.php');
exit();
}
每个文件都是实际的插入查询。(如果你们需要看到他们,我会更新这篇文章)
我遇到的错误是:
SQLSTATE [23000]:完整性约束违规:1452 无法添加或更新子行:外键约束失败(
test
.times
, CONSTRAINTtimes_ibfk_2
FOREIGN KEY (id
) REFERENCESstudents
(id
) ON DELETE CASCADE ON UPDATE CASCADE)
除此之外,第一个查询(students.php 和第二个查询 studentinfo.php)插入得很好。相同的 ID,插入到表中的登录时间出现问题:次。
在 phpmyadmin 中,两个表(studentinfo 和 times)的配置相同,因为学生他/她开始会话(这是 PK ID),所以两者都有级联删除和更新到原始表(学生)。
我该如何解决这个错误?
编辑 :
<?php
require('core/init.php');
try
{
$null = NULL;
$query = $dbh->prepare("INSERT INTO `times` (signintime) VALUES (:signintime)");
$query->bindParam(':signintime' , $null);
$query->execute();
}
catch (PDOException $e)
{
error_log($e->getMessage());
die($e->getMessage());
}
?>