空白屏幕提交将xls导入mysql的表单后

时间:2017-09-26 19:28:04

标签: php excel

这是用于导入它只是在提交带有.xls文件的表单后显示空白页面的代码我不知道它的错误我的代码请帮助我。 我的数据库配置文件没有错误,因为我的sql从xls导入工作正常。

我使用linux服务器

HTML:

    <form action="importData.php" method="post" enctype="multipart/form-data" id="importFrm1">
        <input type="file" name="file" style="margin-top: 30px;px;" /><br>
        <input type="submit" class="btn btn-primary" id="importSubmit" name="importSubmit" value="IMPORT" style="margin-top: 0px;">
    </form>

这是我的php代码:importData.php

 <?php  session_start();
 if(!isset($_SESSION['username'])) {
header("Location:sessionerror.php");
exit;
 }
include "connection2.php";

//load the database configuration file
if(isset($_POST['importSubmit'])){
// Validate whether uploaded file is a csv file
$csvMimes = array('application/vnd.ms-excel','text/csv');
if(!empty($_FILES['file']['name']) && in_array($_FILES['file']['type'],$csvMimes)){

    if(is_uploaded_file($_FILES['file']['tmp_name'])){

        //open uploaded csv file with read only mode
        $csvFile = fopen($_FILES['file']['tmp_name'], 'r');
        //skip first line
        fgetcsv($csvFile);
        // Parse data from csv file line by line
    while (($line = fgetcsv($csvFile,1000, "\t")) !== FALSE){

      $ID=$line[0];
      $projectName=$line[1];
      $projectLocation=$line[2];
      $builderName=$line[3];
      $builderGrade=$line[4];
      $wheatherOCReceived=$line[5];
      $startingPriceRs=$line[6];
      $size_SBA=$line[7];
      $configuration=$line[8];
      $discount=$line[9];
      $segment=$line[10];
      $amenities=$line[11];
      $filenme=$line[12];
      $DateModified=$line[13];

            //check whether member already exists in database with same email
            $prevQuery = "SELECT id FROM info WHERE id = '".$line[0]."'";
            $prevResult = $conn->query($prevQuery);
            if($prevResult->num_rows > 0){
                //update member data
                $conn->query("UPDATE `featured_projects`.`info`
                 SET `projectName`='$projectName',`projectLocation`='$projectLocation',`builderName`='$builderName',`builderGrade`='$builderGrade',`wheatherOCReceived`='$wheatherOCReceived',`startingPriceRs`='$startingPriceRs',`size_SBA`='$size_SBA',`configuration`='$configuration',`discount`='$discount',`segment`='$segment',`amenities`='$amenities',`featuredImage`='$target_file',`date`='$DateModified'
                    WHERE `id` = '".$ID."'") or die("Unable to update: " . $conn->connect_error);
            }else{
                //insert member data into database
                $conn->query("INSERT INTO `featured_projects`.`info` (`id`, `projectName`, `projectLocation`, `builderName`, `builderGrade`, `wheatherOCReceived`, `startingPriceRs`, `size_SBA`, `configuration`, `discount`, `segment`, `amenities`, `featuredImage`, `date`)
                 VALUES ('$ID', '$projectName', '$projectLocation', '$builderName', '$builderGrade', '$wheatherOCReceived', '$startingPriceRs', '$size_SBA', '$configuration', '$discount', '$segment', '$amenities', '$filenme', '$DateModified')" or die("Unable to  Insert: " . $conn->connect_error);
            }
        }
        //close opened csv file
        fclose($csvFile);
        $qstring = '?status=succ';
    }else{
        $qstring = '?status=err';
    }
   }else{
     $qstring = '?status=invalid_file';
   }
  }
   //redirect to the listing page
   header("Location: admin-ready-home-in-bangalore2.php".$qstring);?>

0 个答案:

没有答案