Advertisement
Guest User

PHP DATE PROBLEM

a guest
Jan 13th, 2021
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.27 KB | None | 0 0
  1. <?php
  2. mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
  3. echo "<link rel='stylesheet' href='..\styles.css'>";
  4.  
  5. require('library/php-excel-reader/excel_reader2.php');
  6. require('library/SpreadsheetReader.php');
  7. require('db_config.php');
  8.  
  9.  
  10. if(isset($_POST['Submit'])){
  11.  
  12.  
  13.   $mimes = ['application/vnd.ms-excel','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'];
  14.   if(in_array($_FILES["file"]["type"],$mimes)){
  15.  
  16.  
  17.     $uploadFilePath = 'uploads/'.basename($_FILES['file']['name']);
  18.     move_uploaded_file($_FILES['file']['tmp_name'], $uploadFilePath);
  19.  
  20.  
  21.     $Reader = new SpreadsheetReader($uploadFilePath);
  22.  
  23.  
  24.     $totalSheet = count($Reader->sheets());
  25.  
  26.  
  27.     echo "You have total ".$totalSheet." sheets<br><br>".
  28.  
  29.  
  30.     $html="<table border='2px solid black'>";
  31.     $html.="<tr><th>Description</th><th>Date</th><th>Amount</th><th>Merchant</th><th>Type</th><th>Source</th></tr>";
  32. $query = "Insert Into main(Description,Date,Amount,Merchant,Type,  Source) Values(?, ?, ?, ?, ?, ?)";
  33. $stmp = $mysqli->prepare($query);
  34.  
  35.     /* For Loop for all sheets */
  36.     for($i=0;$i<$totalSheet;$i++){
  37.  
  38.  
  39.       $Reader->ChangeSheet($i);
  40.       foreach ($Reader as $Row)
  41.       {
  42.         $html.="<tr>";
  43.         $des = isset($Row[0]) ? $Row[0] : '';
  44.         $d = isset($Row[1]) ? $Row[1] : '';
  45.      $timestamp = DateTime::createFromFormat('d/m/Y',$d);
  46.   $d1 = $timestamp->format('Y-m-d');
  47.     $a = isset($Row[2]) ? $Row[2] : '';
  48.     $m = isset($Row[3]) ? $Row[3] : '';
  49.     $t = isset($Row[4]) ? $Row[4] : '';
  50.     $s = isset($Row[5]) ? $Row[5] : '';
  51. if($des == '' || $d == '' || $a == '' || $m == '' || $s == '' || $t == ''){continue;}
  52. else{
  53.         $html.="<td>".$des."</td>";
  54.         $html.="<td>".$d1."</td>";
  55.     $html.="<td>".$a."</td>";
  56.     $html.="<td>".$m."</td>";
  57.     $html.="<td>".$t."</td>";
  58.     $html.="<td>".$s."</td>";
  59.         $html.="</tr>";
  60.    
  61.     $stmp->bind_param('sissss', $des, $d1, $a, $m, $t, $s);
  62.     $stmp->execute();
  63.        }
  64.  
  65.  
  66.     }
  67.  
  68.  
  69.     $html.="</table>";
  70.     echo $html;
  71. if(mysqli_error($mysqli) == ''){
  72.     echo "<br />Data Inserted in dababase";}
  73. else{echo "Error: ";
  74.     echo mysqli_error($mysqli);
  75. }};}
  76. else {die("<br/>Sorry, Your File type is not allowed. You can only use a <code>.xlsx</code> file or a <code>.xls</code> file.");
  77.   }
  78.  
  79.  
  80. }
  81.  
  82.  
  83. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement