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 : Sélectionner tout - Visualiser dans une fenêtre à part
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> </p> <p> </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érer la demande : <input style="font-weight:bold; width:70px;" class="sbtn" type="submit" name="submit" value=" insérer " /></td> </tr> </table> <p> </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'); ?>
Partager