59 lines
1.9 KiB
PHP
59 lines
1.9 KiB
PHP
<?php
|
|
require_once 'config.php';
|
|
// conection db
|
|
$conn = require 'connect.php';
|
|
?>
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<title><?php echo $db_site_title." v".$site_version ?></title>
|
|
<!-- <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous"> -->
|
|
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
|
|
<link rel="stylesheet" type="text/css" href="css/gmo.css">
|
|
</head>
|
|
<body>
|
|
<h2><?php echo $db_site_title ?></h2>
|
|
<?php echo $site_copyright; echo "<hr>"; ?>
|
|
<?php
|
|
|
|
// sql to create table
|
|
$sql = "CREATE TABLE IF NOT EXISTS $table (
|
|
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
firstname VARCHAR(30) NOT NULL,
|
|
lastname VARCHAR(30) NOT NULL,
|
|
email VARCHAR(50) UNIQUE,
|
|
reg_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
mod_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
|
)";
|
|
|
|
try {
|
|
$conn->query($sql);
|
|
echo "<p>Table <b>".$table."</b> created successfully</p>";
|
|
}
|
|
catch(PDOException $e) {
|
|
echo $e->getMessage();//Remove or change message in production code
|
|
}
|
|
|
|
// add record from csv files
|
|
$csvFile = fopen($data_csv_file, "r");
|
|
while (($getData = fgetcsv($csvFile, 10000, ";")) !== FALSE){
|
|
// Get row data
|
|
$firstname = $getData[0];
|
|
$lastname = $getData[1];
|
|
$email = $getData[2];
|
|
|
|
$sql = "INSERT INTO $table (firstname, lastname, email) VALUES (?,?,?)";
|
|
try {
|
|
$stmt= $conn->prepare($sql);
|
|
$stmt->execute([$firstname, $lastname, $email]);
|
|
echo "<p>Added '". $firstname. " ". $lastname ."' successfully</p>";
|
|
}
|
|
catch (PDOException $e){
|
|
echo $e->getMessage();;
|
|
}
|
|
}
|
|
$conn=null;
|
|
fclose($csvFile);
|
|
?>
|