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 64 65 66 67 68 69 70
|
<?php
if(isset($_POST["Import"])){
$bdd = new PDO('mysql:host=localhost;dbname=gestion_compte;charset=utf8', 'root', '');
$reponse = $bdd->query('SELECT * FROM conge');
$donnees = $reponse->fetch();
$nom_dusage = $donnees['nom_dusage'];
$prenom = $donnees['prenom'];
$nom_de_famille = $donnees['nom_famille'];
$date_de_naissance = $donnees['date_naissance'];
$categorie = $donnees['categorie'];
$grade = $donnees['grade'];
if($_FILES["file"]["size"] > 0)
{
$file = fopen($_FILES["file"]["tmp_name"], "r");
fgetcsv($file, 767, ";");
while (($getData = fgetcsv($file, 767, ";")) !== FALSE)
{
if ($getData[0] == $nom_dusage AND $getData[1] == $prenom AND $getData[2] == $nom_de_famille AND $getData[3] == $date_de_naissance)
{
echo "<script type=\"text/javascript\">
alert(\"Votre fichier CSV a bien été importé.\");
window.location = \"test.php\"
</script>";
$nb_modifs = $bdd->exec('UPDATE conge SET categorie = "'.$categorie.'\n \n'.$getData[4].' "');
$nb_modifs = $bdd->exec('UPDATE conge SET grade = "'.$grade.'\n \n'.$getData[5].'"');
}
else
{
echo "<br>";
echo "$getData[0]";
echo "<br>";
echo "$nom_dusage";
echo "<br>";
echo "$getData[1]";
echo "<br>";
echo "$prenom";
echo "<br>";
echo "$getData[2]";
echo "<br>";
echo " $nom_de_famille";
echo "<br>";
echo "$getData[3]";
echo "<br>";
echo " $date_de_naissance";
echo "<br>";
echo "<script type=\"text/javascript\">
alert(\"Votre fichier CSV a bien été importé.\");
window.location = \"test.php\"
</script>";
$nb_modifs = $bdd->exec("INSERT into conge (nom_dusage,prenom,nom_famille,date_naissance,categorie,grade) values ('".$getData[0]."','".$getData[1]."','".$getData[2]."','".$getData[3]."','".$getData[4]."','".$getData[5]."')");
}
}
fclose($file);
}
} |
Partager