可以更新外键,但我可以将其删除在两个级联上
我尝试了为此找到的所有解决方案,而其中的无效。
要解释:我正在尝试在表classroom
中更新主键code_class
。此键也是预订
表中的外键。
我保留此错误:
警告:pdostatement :: execute():sqlstate [23000]:完整性 约束违规:1451无法删除或更新父行: 外键约束失败(
ebooking
。保留
,约束recervation_ibfk_3
外键(code_class
)参考classroom
(code_class
)在delete Cascade上的cascade上)in c:\ wamp64 \ www \ last \ ebooking2 \ profile \ admin \ admin \ updateclass.php on Line 38
但是我可以删除相同的密钥。我想提一下,正如错误所说,它们都设置在Cascade
上。
这是我的更新PHP代码
$requete = $bdd->prepare('SELECT * FROM classroom Where code_class = :C ');
$requete->execute(array('C'=> $CR));
while ($donnees = $requete->fetch()){
if (isset($_POST) & !empty($_POST)) {
$data = [
'name' => $_POST['Code'],
'surname' => $_POST['STIME'],
'floor' => $_POST['fTIME'],
'roomtp' => $_POST['ETIME'],
'hard'=> $_POST['HARD'],
'id' => $CR,
];
$sql = "UPDATE classroom SET code_class=:name,capacity=:surname,floor=:floor,room_type=:roomtp,
hardware_type=:hard WHERE code_class=:id ";
$stmt= $bdd->prepare($sql);
$stmt->execute($data);
// echo "<script>window.location.assign('hardware.php')</script>";
}
和我的删除代码,
<?php
// error_reporting(0);
session_start();
include('../../connexionDB.php');
if(!isset($_SESSION['CR']) ||$_SESSION['CR'] == ""){
echo 'no id found';
}else {
$AS = $_SESSION['CR'];
}
echo $AS;
$sql = "DELETE FROM `classroom` WHERE code_class =:c ";
$statement = $bdd->prepare($sql);
$statement->bindParam('c', $AS);
// execute the statement
if ($statement->execute()) {
echo 'publisher id was deleted successfully.';
}
?>
我
ALTER TABLE `reservation` ADD FOREIGN KEY (`code_class`) REFERENCES `classroom`(`code_class`) ON DELETE CASCADE ON UPDATE CASCADE;
看不到问题 - 有人可以帮忙吗?
I tried every solution I can find for this and non of them worked.
To explain: I'm trying to update a primary key code_class
in the table classroom
. This key is also a foreign key in the reservation
table.
I keep gettimg this error:
Warning: PDOStatement::execute(): SQLSTATE[23000]: Integrity
constraint violation: 1451 Cannot delete or update a parent row: a
foreign key constraint fails (ebooking
.reservation
, CONSTRAINTreservation_ibfk_3
FOREIGN KEY (code_class
) REFERENCESclassroom
(code_class
) ON DELETE CASCADE ON UPDATE CASCADE) in
C:\wamp64\www\last\ebooking2\profile\admin\updateClass.php on line
38
But I can delete the same key. I would like to mention that they are both set on CASCADE
, as the error says.
here is my Update php code
$requete = $bdd->prepare('SELECT * FROM classroom Where code_class = :C ');
$requete->execute(array('C'=> $CR));
while ($donnees = $requete->fetch()){
if (isset($_POST) & !empty($_POST)) {
$data = [
'name' => $_POST['Code'],
'surname' => $_POST['STIME'],
'floor' => $_POST['fTIME'],
'roomtp' => $_POST['ETIME'],
'hard'=> $_POST['HARD'],
'id' => $CR,
];
$sql = "UPDATE classroom SET code_class=:name,capacity=:surname,floor=:floor,room_type=:roomtp,
hardware_type=:hard WHERE code_class=:id ";
$stmt= $bdd->prepare($sql);
$stmt->execute($data);
// echo "<script>window.location.assign('hardware.php')</script>";
}
and my delete code
<?php
// error_reporting(0);
session_start();
include('../../connexionDB.php');
if(!isset($_SESSION['CR']) ||$_SESSION['CR'] == ""){
echo 'no id found';
}else {
$AS = $_SESSION['CR'];
}
echo $AS;
$sql = "DELETE FROM `classroom` WHERE code_class =:c ";
$statement = $bdd->prepare($sql);
$statement->bindParam('c', $AS);
// execute the statement
if ($statement->execute()) {
echo 'publisher id was deleted successfully.';
}
?>
the key
ALTER TABLE `reservation` ADD FOREIGN KEY (`code_class`) REFERENCES `classroom`(`code_class`) ON DELETE CASCADE ON UPDATE CASCADE;
I can't see the problem - can someone help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论