-
Notifications
You must be signed in to change notification settings - Fork 0
/
import.php
43 lines (39 loc) · 1.28 KB
/
import.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
<?php
include('sambungan.php');
$namajadual = $_POST['namatable'];
$namafail = $_FILES['namafail']['name'];
$fail = fopen($namafail, "r");
while (!feof($fail)) {
$medan = explode(",", fgets($fail));
if ($namajadual === "pelajar") {
$idpelajar = $medan[0];
$namapelajar = $medan[1];
$idkelas = $medan[2];
$password = $medan[3];
$sql = "insert into pelajar values('$idpelajar', '$namapelajar', '$idkelas', '$password')";
if (mysqli_query($sambungan, $sql))
$berjaya = true;
else
$berjaya = false;
}
if ($namajadual === "soalan") {
$idsoalan = $medan[0];
$namasoalan = $medan[1];
$pilihana = $medan[2];
$pilihanb = $medan[3];
$pilihanc = $medan[4];
$jawapan = $medan[5];
$idguru = $medan[6];
$sql = "insert into soalan values('$idsoalan', '$namasoalan','$pilihana', '$pilihanb', '$pilihanc', '$jawapan', '$idguru')";
if (mysqli_query($sambungan, $sql))
$berjaya = true;
else
$berjaya = false;
}
}
if ($berjaya == true)
echo "<script>alert('Rekod berjaya di import');</script>";
else
echo "<script>alert('Rekod tidak berjaya di import');</script>";
mysqli_close($sambungan);
?>