Allereerst de manier waarop u uw variabelen hebt gedefinieerd op het moment dat Author_ID2 nooit is gedefinieerd:
$AuthorTitle = mysqli_real_escape_string($con, ($_POST['AuthorTitle']));
$AuthorTitle = mysqli_real_escape_string($con, ($_POST['AuthorTitle_ID2']));
Hier overschrijft u gewoon $AuthorTitle
met de waarde van $_POST['AuthorTitle_ID2']
, en definieer niet $AuthorTitle_ID2
helemaal niet.
Vervolgens zou de SQL-instructie zoals u die heeft alleen de tweede author
. linken met de study
in casestudy
omdat LAST_INSERT_ID()
zou de ID van het laatst ingevoegde record alleen retourneren, zelfs als er daadwerkelijk meerdere records waren ingevoegd door één instructie.
En tot slot is er een IF-statement in MySQL :
$AuthorTitle = mysqli_real_escape_string($con, ($_POST['AuthorTitle']));
$AuthorTitle_ID2 = mysqli_real_escape_string($con, ($_POST['AuthorTitle_ID2']));
$F_Name = mysqli_real_escape_string($con, ($_POST['first_name']));
$F_Name_ID2 = mysqli_real_escape_string($con, ($_POST['first_name_ID2']));
$L_Name = mysqli_real_escape_string($con, ($_POST['last_name']));
$L_Name_ID2 = mysqli_real_escape_string($con, ($_POST['last_name_ID2']));
$Email = mysqli_real_escape_string($con, ($_POST['email']));
$Email_ID2 = mysqli_real_escape_string($con, ($_POST['email_ID2']));
$Contactauthor = mysqli_real_escape_string($con, ($_POST['contact']));
$Contactauthor_ID2 = mysqli_real_escape_string($con, ($_POST['contact_ID2']));
$Title = mysqli_real_escape_string($con, ($_POST['Title']));
$Summary = mysqli_real_escape_string($con, ($_POST['Summary']));
mysqli_multi_query($con,"
START TRANSACTION;
INSERT INTO study(Title, Summary)
VALUES('$Title','$Summary');
SET @StudyId = LAST_INSERT_ID();
INSERT INTO author(AuthorTitle, F_Name, L_Name, Email, Contact)
VALUES('$AuthorTitle','$F_Name','$L_Name','$Email','$Contactauthor');
SET @AuthorId = LAST_INSERT_ID();
INSERT INTO casestudy(AuthorId, StudyId, Submitted)
VALUES(@AuthorId, @StudyId, NOW());
IF ('$AuthorTitle_ID2' <> '' OR '$F_Name_ID2' <> '' OR '$L_Name_ID2' <> '' OR '$Email_ID2' <> '' OR '$Contactauthor_ID2' <> '') THEN
INSERT INTO author(AuthorTitle, F_Name, L_Name, Email, Contact)
VALUES('$AuthorTitle_ID2','$F_Name_ID2','$L_Name_ID2','$Email_ID2','$Contactauthor_ID2');
SET @AuthorId = LAST_INSERT_ID();
INSERT INTO casestudy(AuthorId, StudyId, Submitted)
VALUES(@AuthorId, @StudyId, NOW());
END IF;
COMMIT;
");