-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimport.php
More file actions
34 lines (25 loc) · 870 Bytes
/
Copy pathimport.php
File metadata and controls
34 lines (25 loc) · 870 Bytes
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
<?php
use SimpleExcel\SimpleExcel;
if(isset($_POST['import'])){
if(move_uploaded_file($_FILES['excel_file']['tmp_name'],$_FILES['excel_file']['name'])){
require_once('SimpleExcel/SimpleExcel.php');
$excel = new SimpleExcel('csv');
$excel->parser->loadFile($_FILES['excel_file']['name']);
$foo = $excel->parser->getField();
$count = 1;
$db = mysqli_connect('localhost','root','','exceltest');
while(count($foo)>$count){
$roll = $foo[$count][0];
$name = $foo[$count][1];
$email = $foo[$count][2];
$mobile = $foo[$count][3];
$query = "INSERT INTO students (roll_no,name,mobile,email) ";
$query.="VALUES ('$roll','$name','$mobile','$email')";
mysqli_query($db,$query);
$count++;
}
echo "<script>alert('updated');</script>";
header("location:index.php");
}
}
?>