I ma trying to populate a db. The below code is executed in a loop to fill some related tables. When the loop runs 17 times, the "pubmedarticle" and "pubmedarticle_belongsto_user" table are populated with 17 records. However the "abstract" table is populated with 10 records and the other tables with 16 records! There is no restriction in running the loop and it runs exactly 17 times and all the tables should contain 17 records after the loop. I cannot find why there is some missing in the inserting into the db. I appreciate your thoughts.
Here are the primary keys:
pubmedarticle: pubmedArticleId
pubmedarticle_belongsto_user: userId, pubmedArticleId
article: articleId, pubmedArticleId
abstract: abstractId, articleId , pubmedArticleId
pagination: paginationId, articleId, pubmedArticleId
I checked mysqli_error and I recieve this result 6 times (there is 6 missing!): Error description: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's most comprehensive earthquake disaster drill to date. Semistructured interview' at line 1
And this is the code:
mysqli_query($con,"INSERT INTO pubmedarticle (pubmedId) VALUES ('$pmid')");
//------------
$result_last_row = mysqli_query($con, "SELECT pubmedArticleId from pubmedarticle order by pubmedArticleId desc limit 1");
while($row2 = mysqli_fetch_array($result_last_row)) {
$last_userID = $row2['pubmedArticleId'];
}
mysqli_query($con,"INSERT INTO pubmedarticle_belongsto_user (userId, pubmedArticleId) VALUES ('$userId','$last_userID')");
//------------
mysqli_query($con,"INSERT INTO article (pubmedArticleId, articleTitle, articleDate) VALUES ('$last_userID', '$title', '$year_final')");
$result_last_row2 = mysqli_query($con, "SELECT articleId from article order by articleId desc limit 1");
while($row3 = mysqli_fetch_array($result_last_row2)) {
$last_userID_article = $row3['articleId'];
}
if (!mysqli_query($con,"INSERT INTO abstract (articleId, pubmedArticleId, abstractText) VALUES ('$last_userID_article','$last_userID', '$abstract')")){
echo("Error description: " . mysqli_error($con));
echo "</br>";
}
mysqli_query($con,"INSERT INTO pagination (articleId, pubmedArticleId, medlinePgn) VALUES ('$last_userID_article','$last_userID', '$medlinepgn')");
mysqli_query($con,"INSERT INTO publicationtype (articleId, pubmedArticleId, publicationType) VALUES ('$last_userID_article','$last_userID', '$publicationtype')");
mysqli_query($con,"INSERT INTO journal (articleId, pubmedArticleId, issn, journalIssuePubDate, volume, issue, journalTitle, isoAbbreviation)
VALUES ('$last_userID_article','$last_userID', '$issn', '$year_final','$volume', '$issue', '$journalTitle', '$isoAbbreviation')");