csv upload query in php

Solutions on MaxInterview for csv upload query in php by the best coders in the world

showing results for - "csv upload query in php"
César
15 Apr 2016
1<?php
2// Load the database configuration file
3include_once 'dbConfig.php';
4
5// Get status message
6if(!empty($_GET['status'])){
7    switch($_GET['status']){
8        case 'succ':
9            $statusType 'alert-success';
10            $statusMsg 'Members data has been imported successfully.';
11            break;
12        case 'err':
13            $statusType 'alert-danger';
14            $statusMsg 'Some problem occurred, please try again.';
15            break;
16        case 'invalid_file':
17            $statusType 'alert-danger';
18            $statusMsg 'Please upload a valid CSV file.';
19            break;
20        default:
21            $statusType '';
22            $statusMsg '';
23    }
24}
25?>
26
27<!-- Display status message -->
28<?php if(!empty($statusMsg)){ ?>
29<div class="col-xs-12">
30    <div class="alert <?php echo $statusType; ?>"><?php echo $statusMsg; ?></div>
31</div>
32<?php } ?>
33
34<div class="row">
35    <!-- Import link -->
36    <div class="col-md-12 head">
37        <div class="float-right">
38            <a href="javascript:void(0);" class="btn btn-success" onclick="formToggle('importFrm');"><i class="plus"></i> Import</a>
39        </div>
40    </div>
41    <!-- CSV file upload form -->
42    <div class="col-md-12" id="importFrm" style="display: none;">
43        <form action="importData.php" method="post" enctype="multipart/form-data">
44            <input type="file" name="file" />
45            <input type="submit" class="btn btn-primary" name="importSubmit" value="IMPORT">
46        </form>
47    </div>
48
49    <!-- Data list table --> 
50    <table class="table table-striped table-bordered">
51        <thead class="thead-dark">
52            <tr>
53                <th>#ID</th>
54                <th>Name</th>
55                <th>Email</th>
56                <th>Phone</th>
57                <th>Status</th>
58            </tr>
59        </thead>
60        <tbody>
61        <?php
62        // Get member rows
63        $result = $db->query("SELECT * FROM members ORDER BY id DESC");
64        if($result->num_rows > 0){
65            while($row $result->fetch_assoc()){
66        ?>
67            <tr>
68                <td><?php echo $row['id']; ?></td>
69                <td><?php echo $row['name']; ?></td>
70                <td><?php echo $row['email']; ?></td>
71                <td><?php echo $row['phone']; ?></td>
72                <td><?php echo $row['status']; ?></td>
73            </tr>
74        <?php } }else?>
75            <tr><td colspan="5">No member(s) found...</td></tr>
76        <?php } ?>
77        </tbody>
78    </table>
79</div>
80
81<!-- Show/hide CSV upload form -->
82<script>
83function formToggle(ID){
84    var element = document.getElementById(ID);
85    if(element.style.display === "none"){
86        element.style.display = "block";
87    }else{
88        element.style.display = "none";
89    }
90}
91</script>
92