我需要帮助我的phpcode插入表有外键的部分,它无法插入和显示错误。 user是外键。 isTrue是一个tinyint数据类型。我使用的是true,所以我为isTrue列添加了1。
这是显示的错误:
无法添加或更新子行:外键约束失败(project
。statements
,CONSTRAINT fk_statement_user
FOREIGN KEY(user
)参考user
(user
)ON更新没有采取行动的行动
include "dbconn.php";
$statement = $_POST['statement'];
$isTrue = $_POST['isTrue'];
$user = $_POST["user"];
//for($statement=0;$statement<=5;$statement++){
// $query = "INSERT INTO statements(statement, answer, user) VALUES ('$statement','1','junhao') ";
//}
$query = "INSERT INTO statements (statement, isTrue, user) VALUES ('$statement','1','$user')";
$status = mysqli_query($link, $query) or die(mysqli_error($link));
if($status)
{
$row["status"] = $status;
$row["message"] = "Contact record is inserted successfully";
echo json_encode($row);
}else
{
$row["status"] = $status;
$row["message"] = "Create new contact unsuccessful.";
echo json_encode($row);
}