-
Notifications
You must be signed in to change notification settings - Fork 0
/
chart.php
63 lines (35 loc) · 1.53 KB
/
chart.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
<?php
session_start();
if(!isset($_POST["import"])){
header('Location: index.php');
}else{
require_once 'db.php';
try
{
$dbh = new PDO($dsn, $db_config['user'], $db_config['pass'], $options);
define('DB_CONNECTED', true);
$filename = $_FILES["file"]["tmp_name"];
if($_FILES["file"]["size"] > 0)
{
$file = fopen($filename, "r");
while (($getData = fgetcsv($file, 10000, ",")) !== FALSE)
{
$stmt=$dbh->prepare('INSERT INTO users (first_name, country) VALUES(:first_name, :country)');
$stmt->bindValue(':first_name', $getData[0], PDO::PARAM_STR);
$stmt->bindValue(':country', $getData[1], PDO::PARAM_STR);
$result= $stmt->execute();
if($result !== false){
$_SESSION['alert'] = 'Plik zaimportowany poprawnie';
header('Location: index.php');
}else {
$_SESSION['alert'] = 'Wystąpił błąd. Proszę dodaj plik .csv';
header('Location: index.php');
}
}
fclose($file);
}
} catch(PDOException $e)
{
die('Błąd w połączeniu: ' . $e->getMessage());
}
}