-
Notifications
You must be signed in to change notification settings - Fork 0
/
testing.php
92 lines (83 loc) · 2.33 KB
/
testing.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<!DOCTYPE html>
<html>
<head>
<title>Mari Belajar Coding</title>
<?php
// phpinfo();
// include "configuration/config_etc.php";
include "configuration/config_include.php";
// etc();
encryption();
session();
connect();
head();
body();
timing();
?>
</head>
<body>
<table>
<form method="post" enctype="multipart/form-data">
<tr>
<td>Pilih File</td>
<td><input name="filemhsw" type="file" required="required"></td>
</tr>
<tr>
<td></td>
<td><input name="upload" type="submit" value="Import"></td>
</tr>
</form>
</table>
<?php
if (isset($_POST['upload'])) {
require('spreadsheet-reader-master/php-excel-reader/excel_reader2.php');
require('spreadsheet-reader-master/SpreadsheetReader.php');
//upload data excel kedalam folder uploads
$target_dir = "uploads/" . basename($_FILES['filemhsw']['name']);
move_uploaded_file($_FILES['filemhsw']['tmp_name'], $target_dir);
$Reader = new SpreadsheetReader($target_dir);
// foreach ($Reader as $Row)
// {
// print_r($Row);
// }
foreach ($Reader as $Key => $Row) {
// var_dump($Row);
// import data excel mulai baris ke-2 (karena ada header pada baris 1)
if ($Key < 1) continue;
$query = mysqli_query($conn, "INSERT INTO testing(nim,nama,alamat,jurusan) VALUES ('" . $Row[0] . "', '" . $Row[1] . "','" . $Row[2] . "','" . $Row[3] . "')");
}
if ($query) {
echo "Import data berhasil";
} else {
echo mysqli_error($conn);
}
}
?>
<h2>Data Mahasiswa</h2>
<table border="1">
<tr>
<th>No</th>
<th>NIM</th>
<th>Nama</th>
<th>Alamat</th>
<th>Jurusan</th>
</tr>
<?php
$no = 1;
$data = mysqli_query($conn, "select * from testing");
// var_dump($data);
while ($d = mysqli_fetch_assoc($data)) {
?>
<tr>
<td><?= $no++; ?></td>
<td><?= mysqli_real_escape_string($conn, $d['nim']); ?></td>
<td><?= mysqli_real_escape_string($conn, $d['nama']);; ?></td>
<td><?= mysqli_real_escape_string($conn, $d['alamat']); ?></td>
<td><?= mysqli_real_escape_string($conn, $d['jurusan']); ?></td>
</tr>
<?php
}
?>
</table>
</body>
</html>