-
Notifications
You must be signed in to change notification settings - Fork 0
/
import.php
45 lines (41 loc) · 1.62 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
44
45
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<p>Pro nahrání nového ceníku do databáze, stiskni tlačítko "Importovat data".</p>
<form method="post">
<button type="submit" name="btn_import">Importovat data</button>
</form>
<?php
$host = "localhost";
$uname = "pujcovaninaradi";
$pass = "jenikov";
$database = "stroje"; //Change Your Database Name
$conn = new mysqli($host, $uname, $pass, $database);
$conn->set_charset("cp1250");
//CSV To MYSQL MYADDMINPHP
if (isset($_REQUEST['btn_import']))
{
$filename = 'cenik.csv';
$fp = fopen($filename, "r");
$sql = "DELETE FROM ceny";
!$conn->query($sql);
$sql=null;
while (($row = fgetcsv($fp, "0", ",")) != FALSE)
{
$sql = "INSERT INTO ceny (skupina,id,stroj,den,hodina,hodin,vikend,kauce) VALUES('" . implode("','", $row) . "')";
/*INSERT INTO `stroje`.`TABLE 2` (`skupina`, `id`, `stroj`, `den`, `hodina`, `hodin`, `vikend`, `kauce`) VALUES */
if (!$conn->query($sql))
{
echo '<br><span style="text-decoration: underline">Data, která nebylo možno naimportovat:</span><br>' .implode("\",\"", $row);
}
}
echo '<p>Import snad proběhl v pořádku. :)</p>';
fclose($fp);
}
?>
</body>
</html>