Tout d'abord, la façon dont vos variables sont définies pour le moment Author_ID2 n'est jamais défini :
$AuthorTitle = mysqli_real_escape_string($con, ($_POST['AuthorTitle']));
$AuthorTitle = mysqli_real_escape_string($con, ($_POST['AuthorTitle_ID2']));
Ici, vous remplacez simplement $AuthorTitle
avec la valeur de $_POST['AuthorTitle_ID2']
, et ne définissez pas $AuthorTitle_ID2
du tout.
Ensuite, l'instruction SQL telle que vous l'avez ne lierait que le deuxième author
avec l'study
dans casestudy
car LAST_INSERT_ID()
renverrait l'ID du dernier enregistrement inséré uniquement même s'il y avait en fait plusieurs enregistrements insérés par une instruction.
Et enfin, il y a instruction IF dans 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;
");