I need help for my phpcode at inserting part where the table have a foreign key and its not able to insert and showing error. user is a foreign key . isTrue is a tinyint datatype. I am using true so i added 1 for isTrue column.
Here is the error displayed : Cannot add or update a child row: a foreign key constraint fails (project
.statements
, CONSTRAINT fk_statement_user
FOREIGN KEY (user
) REFERENCES user
(user
) ON DELETE NO ACTION ON UPDATE NO ACTION)
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);
}