Précédent   Forum des professionnels en informatique > PHP > PHP & SGBD > PHP & MySQL
PHP & MySQL Forum d'entraide sur les fonctions MySQL avec PHP. Avant de poster -> FAQ MySQL, Cours MySQL et Sources MySQL. Pour les questions concernant le moteur MySQL plutôt que les fonctions PHP, merci d'utiliser le forum MySQL.
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 05/07/2011, 13h23   #1
 
Inscription : septembre 2008
Messages : 114
Détails du profil
Informations forums :
Inscription : septembre 2008
Messages : 114
Points : -49
Points : -49
Par défaut Insérer le contenu d'un fichier Excel dans une base de donnée Mysql

Bonjour,

Je cherche à insérer les données d'un fichier excel dans une base de donnée mysql .

Tout passe bien , mais lorsqu'il y a un champ vide l'insertion s'insère mais vide.


Code :
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
 
<?php
include("include/connexion.php");
include("function.php");
?>
<form   id="form1" name="form1" enctype="multipart/form-data" method="post" action="">
  <label>
  <select name="activite" id="activite">
    <option value="1">Informatique</option>
    <option value="2">Restaurant</option>
  </select>
  </label>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <table width="755" border="0" cellpadding="3" cellspacing="0">
    <tr>
      <td width="169">Inserer votre Fichier ici :</td>
      <td colspan="2"><input name="xls" type="file" id="xls"  size="50" />      </td>
    </tr>
    <tr>
      <td height="25" colspan="3"><label></label></td>
    </tr>
    <tr>
      <td></td>
      <td colspan="2"> Pour ins&eacute;rer la demande :
        <input  style="font-weight:bold; width:70px;" class="sbtn" type="submit" name="submit" value=" ins&eacute;rer " /></td>
    </tr>
  </table>
  <p>&nbsp;</p>
</form>
<script> 
<!-- 
// 
 
 var seconds=7 
 //document.counter.d2.value='30' 
 
function display(){ 
 
    seconds-=1 
if(seconds==1){ document.getElementById("load").style.display = "none";}
   else{ setTimeout("display()",100) 
	//document.counter.d2.value=seconds;
	}
} 
 
--> 
</script> 
 
  <?php
  if($_POST){
  $id_activite=$_POST['activite'];
  $nom_xls = $_FILES['xls']['name'];
  $type = $_FILES['xls']['type'];
 
 
  if (is_uploaded_file($_FILES['xls']['tmp_name']))
     {
     move_uploaded_file($_FILES['xls']['tmp_name'],$nom_xls);
 
     }
 
 }
if(isset($nom_xls) and !empty($nom_xls))
{
echo '<div style="height:20px;">
 <div align="center" id="load" style="display: block"><img src="images/loading.gif" /> </div><br/>
</div>';
	echo '<script language="javascript"> display() </script> '; 
include('include/reader.php');
//require_once 'oleread.inc';
$data = new Spreadsheet_Excel_Reader();
 
// Définir l'encodage
 
$data->setOutputEncoding('CP1251');
// Faire en sorte que les indices commencent à 0
 
$data->setRowColOffset(0);
// Lire le fichier
 
$data->read($nom_xls) ;
if($data->sheets[0]['numRows']!=0) 
echo "<span style='color:#51AB28' ><br>le Fichier <b>". $nom_xls."</b> valide</span>";
else echo "<span style='color:red' ><br><b>Erreur ! : </b>le Fichier <b>". $nom_xls."</b> est Vide .</span>";
// Afficher toutes les cellules de la première feuille (sheets[0])
 $today = date("j / n / Y");
 
for ($y = 1; $y < $data->sheets[0]['numRows']; ++$y) {
echo '<br>';
 for ($x = 0; $x < $data->sheets[0]['numCols']; ++$x) {
 
   @$d[$x]=$data->sheets[0]['cells'][$y][$x];
 
 
 if($d[2]=="")
$nb_doubl=0;
else{
$doublon= "SELECT * FROM `entreprise` where email=\"$d[2]\" "; 
$result = mysql_query($doublon) or die (mysql_error());
$nb_doubl=mysql_num_rows($result);
}
if($nb_doubl==0){
mysql_query("INSERT INTO `entreprise`(`id_entreprise`,`nom_entreprise`, `ville`, `email`) VALUES('', '".$d[0]."', '".$d[1]."', '".$d[2]."')")or die (mysql_error()); 
echo  " - ".$d[1]." ".$d[2]."<span style='color:#69B524' > (Inseré)</span>"; 
}
else echo  " - ".$d[1]." ".$d[2]."<span style='color:#FF0000' > (Doublon)</span>";
}
 
}
}
 @unlink($nom_xls);
//include('distribution_fiche.php');
?>
ghir_ana est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 05/07/2011, 13h59   #2
Membre éclairé
 
Homme Jérémy
Étudiant
Inscription : octobre 2009
Messages : 236
Détails du profil
Informations personnelles :
Nom : Homme Jérémy
Localisation : France

Informations professionnelles :
Activité : Étudiant
Secteur : High Tech - Produits et services télécom et Internet

Informations forums :
Inscription : octobre 2009
Messages : 236
Points : 322
Points : 322
Citation:
Envoyé par ghir_ana Voir le message
Tout passe bien , mais lorsqu'il y a un champ vide l'insertion s'insère mais vide.
Peux-tu préciser le problème, car l'insertion de la valeur vide est normale.
gwharl est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 05/07/2011, 15h46   #3
 
Inscription : septembre 2008
Messages : 114
Détails du profil
Informations forums :
Inscription : septembre 2008
Messages : 114
Points : -49
Points : -49
Citation:
Envoyé par gwharl Voir le message
Peux-tu préciser le problème, car l'insertion de la valeur vide est normale.

Non tous les insertions qui suivent cette valeur s' insert vide
ghir_ana est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 03h08.


 
 
 
 
Partenaires

Hébergement Web