Here is my code where I think something is going wrong. Could anyone shed some light on this please?
Code: Select all
<?php
//truncate table
mysqli_fetch_array(mysqli_query($con,'TRUNCATE TABLE `student`'));
mysqli_fetch_array(mysqli_query($con,'TRUNCATE TABLE `stumod`'));
//code to import into db from $importData
if(is_array($importData)){
foreach($importData as $d){
//insert student row
mysqli_fetch_array(mysqli_query($con,'INSERT INTO `student` (`studentId`,`tutorId`,`part`,`email`,`firstname`,`surname`) VALUES ('.(int)$d[1].','.(int)$d[7].','.(int)$d[8].',\''.($d[9]).'\',\''.$d[3].'\',\''.$d[2].'\')'));
//insert 3 modules - from the 3 columns on the spreadsheet
mysqli_fetch_array(mysqli_query($con,'INSERT INTO `stumod` (`studentId`,`moduleCode`) VALUES ('.(int)$d[1].',\''.mysql_real_escape_string($d[4]).'\')'));
mysqli_fetch_array(mysqli_query($con,'INSERT INTO `stumod` (`studentId`,`moduleCode`) VALUES ('.(int)$d[1].',\''.mysql_real_escape_string($d[5]).'\')'));
mysqli_fetch_array(mysqli_query($con,'INSERT INTO `stumod` (`studentId`,`moduleCode`) VALUES ('.(int)$d[1].',\''.mysql_real_escape_string($d[6]).'\')'));
}
//voila
}
} else {
//PRINT AN ERROR IF THE FILE COULD NOT BE COPIED
?>