我只能导入下表中的4个条目,之后我收到未定义的偏移量错误

时间:2019-12-21 04:53:52

标签: php html css

由于遇到偏移错误,请在此处输入代码,在导入下表/数据库中的数据时遇到困难。

<?php
$conn = mysqli_connect("localhost", "root", "", "rms");

if (isset($_POST["import"])) {

    $fileName = $_FILES["file"]["tmp_name"];

    if ($_FILES["file"]["size"] > 0)
    {
          $file = fopen($fileName, "r");

        while (($column = fgetcsv($file, 1000, ",")) !== FALSE) {

        *$sqlInsert = "INSERT into user (user_code, user_fname, user_mname, user_lname, user_mobile, user_telephone, user_email, user_dob) values ('" . $column[0] . "'," . $column[1] . "','" . $column[2] . "','" . $column[3] . "','" . $column[4] . "','" . $column[5] . "','" . $column[6] . "','" . $column[7] . "')";
            $result = mysqli_query($conn, $sqlInsert);

            if (! empty($result)) 
            {
                $type = "success";
                $message = "CSV Data Imported into the Database";
            }
            else
                {
                $type = "error";
                $message = "Problem in Importing CSV Data";
            }
        }*
    }
}
?>
<!DOCTYPE html>
<html>

<head>
<script src="jquery-3.2.1.min.js"></script>

<style>
body {
    font-family: Arial;
    width: 100%;
}

.outer-scontainer {
    background: #F0F0F0;
    border: #e0dfdf 1px solid;
    padding: 20px;
    border-radius: 2px;
}

.input-row {
    margin-top: 0px;
    margin-bottom: 20px;
}

.btn-submit {
    background: #333;
    border: #1d1d1d 1px solid;
    color: #f0f0f0;
    font-size: 0.9em;
    width: 100px;
    border-radius: 2px;
    cursor: pointer;
}

.outer-scontainer table {
    border-collapse: collapse;
    width: 100%;
}

.outer-scontainer th {
    border: 1px solid #dddddd;
    padding: 8px;
    text-align: left;
}

.outer-scontainer td {
    border: 1px solid #dddddd;
    padding: 8px;
    text-align: left;
}

#response {
    padding: 10px;
    margin-bottom: 10px;
    border-radius: 2px;
    display:none;
}

.success {
    background: #c7efd9;
    border: #bbe2cd 1px solid;
}

.error {
    background: #fbcfcf;
    border: #f3c6c7 1px solid;
}

div#response.display-block {
    display: block;
}
</style>
<script type="text/javascript">
$(document).ready(function() {
    $("#frmCSVImport").on("submit", function () {

        $("#response").attr("class", "");
        $("#response").html("");
        var fileType = ".csv";
        var regex = new RegExp("([a-zA-Z0-9\s_\\.\-:])+(" + fileType + ")$");
        if (!regex.test($("#file").val().toLowerCase())) {
                $("#response").addClass("error");
                $("#response").addClass("display-block");
            $("#response").html("Invalid File. Upload : <b>" + fileType + "</b> Files.");
            return false;
        }
        return true;
    });
});
</script>
</head>

<body>
    <h2>Import CSV file into Mysql using PHP</h2>

    <div id="response" class="<?php if(!empty($type)) { echo $type . " display-block"; } ?>"><?php if(!empty($message)) { echo $message; } ?></div>
    <div class="outer-scontainer">
        <div class="row">

            <form class="form-horizontal" action="" method="post"
                name="frmCSVImport" id="frmCSVImport" enctype="multipart/form-data">
                <div class="input-row">
                    <label class="col-md-4 control-label">Choose CSV
                        File</label> <input type="file" name="file"
                        id="file" accept=".csv">
                    <button type="submit" id="submit" name="import"
                        class="btn-submit">Import</button>
                    <br />

                </div>

            </form>

        </div>












            <?php
            $sqlSelect = "SELECT * FROM user";
            $result = mysqli_query($conn, $sqlSelect);

            if (mysqli_num_rows($result) > 0) {
                ?>
            <table id='userTable'>
            <thead>
                <tr>
                    <th>User Code</th>
                    <th>First Name</th>
                    <th>Middle Name</th>
                    <th>Last Name</th>

                    <th>Mobile</th>
                    <th>Telephone</th>
                    <th>Email</th>
                    <th>Date of Birth</th>

                </tr>
            </thead>
<?php

                while ($row = mysqli_fetch_array($result)) {
                    ?>

                <tbody>
                <tr>
                    <td><?php  echo $row['user_code']; ?></td>
                    <td><?php  echo $row['user_fname']; ?></td>
                    <td><?php  echo $row['user_mname']; ?></td>
                    <td><?php  echo $row['user_lname']; ?></td>

                    <td><?php  echo $row['user_mobile']; ?></td>
                    <td><?php  echo $row['user_telephone']; ?></td>
                    <td><?php  echo $row['user_email']; ?></td>
                    <td><?php  echo $row['user_dob']; ?></td>
                </tr>
                    <?php
                }
                ?>
                </tbody>
        </table>
        <?php } ?>
    </div>

</body>

</html>

这是以下错误

注意:未定义的偏移量:第13行的D:\ xampp \ htdocs \ import \ index.php中的5

注意:未定义的偏移量:第13行D:\ xampp \ htdocs \ import \ index.php中的6

注意:未定义的偏移量:第13行D:\ xampp \ htdocs \ import \ index.php中的7

注意:未定义的偏移量:第13行的D:\ xampp \ htdocs \ import \ index.php中的5

注意:未定义的偏移量:第13行D:\ xampp \ htdocs \ import \ index.php中的6

注意:未定义的偏移量:第13行D:\ xampp \ htdocs \ import \ index.php中的7

0 个答案:

没有答案