uploadsubmit.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <?php
  2. require('/client-assets/php/spreadsheet/php-excel-reader/excel_reader2.php');
  3. require('/client-assets/php/spreadsheet/SpreadsheetReader.php');
  4. $dbHost = "localhost";
  5. $dbDatabase = "cropmonitor";
  6. $dbPasswrod = "brvnCcaEYxlPCS3";
  7. $dbUser = "cropmonitor";
  8. $mysqli = new mysqli($dbHost, $dbUser, $dbPasswrod, $dbDatabase);
  9. //$con = mysqli_connect("localhost", "cropmonitor", "brvnCcaEYxlPCS3", "cropmonitor");
  10. if(isset($_POST['Submit'])){
  11. $mimes = ['application/vnd.ms-excel','text/xls','text/xlsx','text/csv','application/vnd.oasis.opendocument.spreadsheet'];
  12. if(in_array($_FILES["file"]["type"],$mimes)){
  13. $uploadFilePath = '/client-assets/uploads/'.basename($_FILES['file']['name']); //need to add individual folders for clients.
  14. move_uploaded_file($_FILES['file']['tmp_name'], $uploadFilePath);
  15. $Reader = new SpreadsheetReader($uploadFilePath);
  16. $totalSheet = count($Reader->sheets());
  17. echo "You have total ".$totalSheet." sheets".
  18. $html="<table border='1'>";
  19. /* For Loop for all sheets */
  20. for($i=0;$i<$totalSheet;$i++){
  21. $Reader->ChangeSheet($i);
  22. foreach ($Reader as $Row)
  23. {
  24. $html.="<tr>";
  25. $title = isset($Row[0]) ? $Row[0] : '';
  26. $description = isset($Row[1]) ? $Row[1] : '';
  27. $html.="<td>".id."</td>";
  28. $html.="<td>".analysis_type."</td>";
  29. $html.="<td>".lab_no."</td>";
  30. $html.="<td>".batch_no."</td>";
  31. $html.="<td>".sample_id."</td>";
  32. $html.="<td>".site_id."</td>";
  33. $html.="<td>".crop."</td>";
  34. $html.="<td>".date_sampled."</td>";
  35. $html.="<td>".lab_no."</td>";
  36. $html.="<td>".batch_no."</td>";
  37. $html.="<td>".sample_id."</td>";
  38. $html.="<td>".site_id."</td>";
  39. $html.="<td>".tec."</td>";
  40. $html.="<td>".cec."</td>";
  41. $html.="<td>".texture."</td>";
  42. $html.="<td>".gravel."</td>";
  43. $html.="<td>".colour."</td>";
  44. $html.="<td>".NO3_N."</td>";
  45. $html.="<td>".NH3_N."</td>";
  46. $html.="<td>".p_mehlick."</td>";
  47. $html.="<td>".p_bray2."</td>";
  48. $html.="<td>".p_morgan."</td>";
  49. $html.="<td>".k_morgan."</td>";
  50. $html.="<td>".ca_morgan."</td>";
  51. $html.="<td>".mg_morgan."</td>";
  52. $html.="<td>".na_morgan."</td>";
  53. $html.="<td>".ch_h2o."</td>";
  54. $html.="<td>".ocarbon."</td>";
  55. $html.="<td>".omatter."</td>";
  56. $html.="<td>".fe."</td>";
  57. $html.="<td>".ec."</td>";
  58. $html.="<td>".ph_cacl2."</td>";
  59. $html.="<td>".ph_h2o."</td>";
  60. $html.="<td>".paramag."</td>";
  61. $html.="<td>".s_morgan."</td>";
  62. $html.="<td>".b_cacl2."</td>";
  63. $html.="<td>".mn_dtpa."</td>";
  64. $html.="<td>".zn_dtpa."</td>";
  65. $html.="<td>".fe_dtpa."</td>";
  66. $html.="<td>".cu_dtpa."</td>";
  67. $html.="<td>".al."</td>";
  68. $html.="<td>".sl_cacl2."</td>";
  69. $html.="<td>".m_dtpa."</td>";
  70. $html.="<td>".co_dtpa."</td>";
  71. $html.="<td>".se."</td>";
  72. $html.="<td>".ca_mehlick3."</td>";
  73. $html.="<td>".mg_mehlick3."</td>";
  74. $html.="<td>".k_mehlick3."</td>";
  75. $html.="<td>".na_mehlick3."</td>";
  76. $html.="<td>".al_mehlick3."</td>";
  77. $html.="</tr>";
  78. $query = "insert into soil_records(
  79. analysis_type,
  80. lab_no,
  81. batch_no,
  82. sample_id,
  83. site_id,
  84. crop,
  85. date_sampled,
  86. lab_no,
  87. batch_no,
  88. sample_id,
  89. site_id,
  90. tec,
  91. cec,
  92. texture,
  93. gravel,
  94. colour,
  95. NO3_N,
  96. NH3_N,
  97. p_mehlick,
  98. p_bray2,
  99. p_morgan,
  100. k_morgan,
  101. ca_morgan,
  102. mg_morgan,
  103. na_morgan,
  104. ch_h2o,
  105. ocarbon,
  106. omatter,
  107. fe,
  108. ec,
  109. ph_cacl2,
  110. ph_h2o,
  111. paramag,
  112. s_morgan,
  113. b_cacl2,
  114. mn_dtpa,
  115. zn_dtpa,
  116. fe_dtpa,
  117. cu_dtpa,
  118. al,
  119. sl_cacl2,
  120. m_dtpa,
  121. co_dtpa,
  122. se,
  123. ca_mehlick3,
  124. mg_mehlick3,
  125. k_mehlick3,
  126. na_mehlick3,
  127. al_mehlick3
  128. ) values(
  129. '" . $analysis_type . "',
  130. '" . $lab_no . "',
  131. '" . $batch_no . "',
  132. '" . $sample_id . "',
  133. '" . $site_id . "',
  134. '" . $crop . "',
  135. '" . $date_sampled . "',
  136. '" . $lab_no . "',
  137. '" . $batch_no . "',
  138. '" . $sample_id . "',
  139. '" . $site_id . "',
  140. '" . $tec . "',
  141. '" . $cec . "',
  142. '" . $texture . "',
  143. '" . $gravel . "',
  144. '" . $colour . "',
  145. '" . $NO3_N . "',
  146. '" . $NH3_N . "',
  147. '" . $p_mehlick . "',
  148. '" . $p_bray2 . "',
  149. '" . $p_morgan . "',
  150. '" . $k_morgan . "',
  151. '" . $ca_morgan . "',
  152. '" . $mg_morgan . "',
  153. '" . $na_morgan . "',
  154. '" . $ch_h2o . "',
  155. '" . $ocarbon . "',
  156. '" . $omatter . "',
  157. '" . $fe . "',
  158. '" . $ec . "',
  159. '" . $ph_cacl2 . "',
  160. '" . $ph_h2o . "',
  161. '" . $paramag . "',
  162. '" . $s_morgan . "',
  163. '" . $b_cacl2 . "',
  164. '" . $mn_dtpa . "',
  165. '" . $zn_dtpa . "',
  166. '" . $fe_dtpa . "',
  167. '" . $cu_dtpa . "',
  168. '" . $al . "',
  169. '" . $sl_cacl2 . "',
  170. '" . $m_dtpa . "',
  171. '" . $co_dtpa . "',
  172. '" . $se . "',
  173. '" . $ca_mehlick3 . "',
  174. '" . $mg_mehlick3 . "',
  175. '" . $k_mehlick3 . "',
  176. '" . $na_mehlick3 . "',
  177. '" . $al_mehlick3 . "'
  178. )";
  179. $mysqli->query($query);
  180. }
  181. }
  182. $html.="</table>";
  183. echo $html;
  184. echo "<br />Data Inserted in dababase";
  185. }else {
  186. die("<br/>Sorry, Incorrect file.");
  187. }
  188. }