Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 未上载CSV文件_Php - Fatal编程技术网

Php 未上载CSV文件

Php 未上载CSV文件,php,Php,以下是上载csv文件的代码。少数文件正确上载,但少数文件未正确上载。它说“成员数据已成功插入”。但当我看到数据库时,记录不在那里 请检查一下代码,如果有错误请告诉我 <?php //load the database configuration file include 'csv_css.css'; include 'dbConfig.php'; if(!empty($_GET['status'])){ switch($_GET['status']){ case

以下是上载csv文件的代码。少数文件正确上载,但少数文件未正确上载。它说“成员数据已成功插入”。但当我看到数据库时,记录不在那里 请检查一下代码,如果有错误请告诉我

<?php
//load the database configuration file
include 'csv_css.css';
include 'dbConfig.php';

if(!empty($_GET['status'])){
    switch($_GET['status']){
        case 'succ':
            $statusMsgClass = 'alert-success';
            $statusMsg = 'Members data has been inserted successfully.';
            break;
        case 'err':
            $statusMsgClass = 'alert-danger';
            $statusMsg = 'Some problem occurred, please try again.';
            break;
        case 'invalid_file':
            $statusMsgClass = 'alert-danger';
            $statusMsg = 'Please upload a valid CSV file.'; 
            break;
        default:
            $statusMsgClass = '';
            $statusMsg = '';
       }
}
?>
 <div class="container">
<?php if(!empty($statusMsg)){
     echo '<div class="alert '.$statusMsgClass.'">'.$statusMsg.'</div>';
  } 
?>
   <div class="panel panel-default">
    <div class="panel-heading">
        Members list
        <a href="javascript:void(0);" onclick="$('#importFrm').slideToggle();">Import Members</a>
    </div>
    <div class="panel-body">
        <form action="import_usait.php" method="post" enctype="multipart/form-data" id="importFrm">
            <input type="file" name="file" />
            <input type="submit" class="btn btn-primary" name="importSubmit" value="IMPORT">
        </form>
        <table class="table table-bordered">
            <thead>
                <tr>
                  <th>ContactOwner</th>
                  <th>LeadSource</th>
                  <th>Firstname</th>
                  <th>Lastname</th>
                  <th>Accountname</th>
                  <th>Title</th>
                  <th>EmailID</th>
                  <th>Department</th>
                  <th>Industry</th>
                  <th>Phone</th>
                  <th>Mobile</th>
                  <th>Fax</th>
                  <th>DOB</th>
                  <th>Asssistant</th>
                  <th>Asstphone</th>
                  <th>ReportsTo</th>
                  <th>LinkedIn</th>
                  <th>Street</th>
                  <th>OtherStreet</th>
                  <th>City</th>
                  <th>State</th>
                  <th>Zip</th>
                  <th>Country</th>
                  <th>Description</th>
                </tr>
            </thead>
            <tbody>
<?php
    //get records from database
    $query = $db->query("SELECT * FROM contact ORDER BY id DESC");
    if($query->num_rows > 0){ 
        while($row = $query->fetch_assoc()){ ?>
                <tr>
                  <td><?php echo $row['id']; ?></td>
                  <td><?php echo $row['ContactOwner']; ?></td>
                  <td><?php echo $row['LeadSource']; ?></td>
                  <td><?php echo $row['Firstname']; ?></td>
                  <td><?php echo $row['Lastname']; ?></td>
                  <td><?php echo $row['Accountname']; ?></td>
                  <td><?php echo $row['Title']; ?></td>
                  <td><?php echo $row['EmailID'];?></td>
                  <td><?php echo $row['Department'];?></td>
                  <td><?php echo $row['Industry'];?></td>
                  <td><?php echo $row['Phone']; ?></td>
                  <td><?php echo $row['Mobile']; ?></td>
                  <td><?php echo $row['Fax'];?></td>
                  <td><?php echo $row['DOB'];?></td>
                  <td><?php echo $row['Asssistant'];?></td>
                  <td><?php echo $row['Asstphone'];?></td>
                  <td><?php echo $row['ReportsTo'];?></td>
                  <td><?php echo $row['LinkedIn'];?></td>
                  <td><?php echo $row['Street'];?></td>
                  <td><?php echo $row['OtherStreet'];?></td>
                  <td><?php echo $row['City']; ?></td>
                  <td><?php echo $row['State'];?></td>
                  <td><?php echo $row['Zip'];?></td>  
                  <td><?php echo $row['Country'];?></td>
                  <td><?php echo $row['Description'];?></td>
              </tr>
<?php 
        } 
    }else{ 
?>
                <tr><td colspan="25">No member(s) found.....</td></tr>
<?php } ?>
            </tbody>
        </table>
    </div>
  </div>
 </div>

成员名单
联系人所有者
铅源
名字
姓氏
帐户名
标题
电子邮件ID
部门
工业
电话
可移动的
传真
出生日期
助手
助理电话
报告
LinkedIn
街头
其他街道
城市
陈述
拉链
国家
描述
找不到成员。。。。。
导入_usait.php文件:

<?php
//load the database configuration file
include 'dbConfig.php';

if(isset($_POST['importSubmit'])){

    //validate whether uploaded file is a csv file
    $csvMimes = array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'application/x-csv', 'text/x-csv', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel', 'text/plain');

    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)) !== FALSE){
                //check whether member already exists in database with same Category
                //insert member data into database
                $db->query("INSERT INTO contact 
                                (ContactOwner, LeadSource, Firstname, 
                                Lastname,Accountname, Title, 
                                EmailID, Department,Industry, 
                                Phone, Mobile, Fax, DOB, Assistant, 
                                Asstphone, ReportsTo, LinkedIn, Street, 
                                OtherStreet, City, State, Zip, 
                                Country, Description) 
                        VALUES 
                            ('".$line[0]."','".$line[1]."','".$line[2].
                            "','".$line[3]."','".$line[4]."','".$line[5].
                            "','".$line[6]."','".$line[7]."','".$line[8].
                            ",'".$line[9]."','".$line[10].",'".$line[11]."','".$line[12].",'".$line[13].
                            "','".$line[14].",'".$line[15]."','".$line[16].",'".$line[17].
                            "','".$line[18].",'".$line[19]."','".$line[20].",'".$line[21].
                            "','".$line[22].",'".$line[23]."')");
            }

            //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: usa_it.php".$qstring);

我自己还没有运行这个,但我认为您的mime检查在您检查时是一个失误。首先查看是否已上载\u文件(),然后检查mime。此阶段的Mime类型由浏览器报告,可能是奇怪的/错误的/丢失的或危险的。不要相信它。

了解防止SQL注入的预处理语句可能是大小问题?检查日志。如果在某个地方出现任何错误,它应该显示在那里。在打开PHP标记后立即进行测试时,将其添加到文件的顶部,例如
,如果您正在使用
MYSQLI\uu
Add
ini\u集('display\u errors',1);ini_集(“日志错误”,1);错误报告(E_全部);mysqli_报告(mysqli_报告错误| mysqli_报告严格)到脚本的顶部。这将强制任何
mysqli\uuu
错误生成您可以在浏览器上看到的异常,其他错误也将在浏览器上可见。