My question is very similar to this question. However, unlike in this question my array does not have fieldname values. My array looks like this:
Array
(
[0] => Array
(
[0] => Extraction and characterisation of gelatin from the skin of striped catfish (Pangasianodon hypophthalmus) and studies on its colour improvement
[1] => EMAIL FREE FULL TEXT DOWNLOAD FULL TEXT
[2] => Prabjeet Singh, Soottawat Benjakul
[3] => 1-9
[4] => http://dx.doi.org/10.5897/AJB2013.13121
)
[1] => Array
(
[0] => Electrolyte ions and glutathione enzymes as stress markers in Argania spinosa subjected to drought stress and recovery
[1] => EMAIL FREE FULL TEXT DOWNLOAD FULL TEXT
[2] => Abdelghani Chakhchar, Mouna Lamaoui, Salama Aissam, Abderrahim Ferradous, Said Wahbi, Abdelhamid EI Mousadik, Saad Ibnsouda-Koraichi, Abdelkarim Filali-Maltouf, Cherkaoui El Modafar
[3] => 10-21
[4] => http://dx.doi.org/10.5897/AJB2016.15234
)
[2] => Array
(
[0] => Molecular detection of disease resistance genes to powdery mildew (Blumeria graminis f. sp. tritici) in wheat (Triticum aestivum) cultivars
[1] => EMAIL FREE FULL TEXT DOWNLOAD FULL TEXT
[2] => Vincent Mgoli Mwale, Xiuli Tang, Eric Chilembwe
[3] => 22-31
[4] => http://dx.doi.org/10.5897/AJB2016.15720
)
)
I am trying to get this array data into a mysql table. The php code i am using looks like this(see below):
foreach ($newref as $key=>$values){
$title = $values[0];
$authors = $values[2];
$pages = $values[3];
$doi = $values[4];
$query = "INSERT INTO citations (id,title,authors,pages,doi) VALUES (:title,:authors,:pages,:doi)";
$sql=$con->prepare($query);
$sql->execute(array(
':title' => $title,
':authors' => $authors,
':pages' => $pages,
':doi' => $doi
));
}
Somehow i am not able to insert data into the table. My Db connection is okay and is not reporting any errors. What can i be possibly doing wrong? What is the best/easier way of inserting this kind of data into a mysql table? I am at my wits end...Thanking you in advance