par
hiker » 28 oct. 2010, 12:42
Bonjour!
Je viens à vous pour vous soumettre mon problème.
En effet je cherche à charger un fichier CSV dans ma base de données à travers le code suivant mais ça fonctionne pas
Code : Tout sélectionner
<form action= "<?php echo $_SERVER['PHP_SELF'];?>" method="post" enctype="application/x-www-form-urlencoded">
<fieldset style="width:600px">
<legend><b><h6>Précharger white liste</h6></b></legend>
<table width="80%" class="centre_tab2">
<tr><td align="right"><label for="services">Liste des services:</label></td>
<td><select name="SERVICES" id="services">
<option value="club20">CLUB20</option>
<option value="yabusiness">YA BUSINESS</option>
<option value="internetmobil">INTERNET MOBIL</option>
<option value="familleami">FAMILLE AMIS</option>
<option value="nexs">NEWS</option>
<option value="pharmacies">PHARMACIES</option>
</select></td></tr>
<tr><td align="right">Nom du Fichier</td>
<td><input type="file" name="file" /></td>
<td><input name="submit" type="submit" value="Charger" /></td></tr>
</table>
</fieldset>
<?php
$data = array();
function charge_numero($first)
{
global $data;
$data []= array(
'first' => $first);
//include ("connexion_bd.php");
// if ($_SESSION['login']!=NULL){
ini_set('display_errors','1');
//Inclusion de la classe mère
include ("SGBD.class.php");
/* Initialisation de la variable du SGBD correspondant */
$SQL = "MySQL";
// Inclusion de la classe fille du SGBD correspondant
include ($SQL.".SGBD.class.php");
/* Création d'un nouvel objet de la classe fille + lancement du constructeur */
$database = new $SQL('root', '', 'localhost', 'dbprojet');
// Connection à la base de données
$database->connect();
$database->requete("INSERT INTO WHITE_LISTE VALUES ('', $first , 'zszszzsx')");
}
$fichier=isset($_FILES["file"]["tmp_name"]);
if ( $fichier )
{
$dom = DOMDocument::load( $_FILES['file']['tmp_name'] );
$rows = $dom->getElementsByTagName( 'Row' );
$first_row = true;
foreach ($rows as $row)
{
if (!$first_row )
{
$first = "";
$index = 1;
$cells = $row->getElementsByTagName( 'Cell' );
foreach( $cells as $cell )
{
$ind = $cell->getAttribute( 'Index' );
if ( $ind != null ) $index = $ind;
if ( $index == 1 ) $first = $cell->nodeValue;
$index += 1;
}
charge_numero($first);
}
$first_row = false;
}
echo 'zzzzzzzzzzzzzzzzzzzzzzzz';
}
?>
</form>
Voici le code sql de ma table
/*==============================================================*/
/* Table : WHITE_LISTE */
/*==============================================================*/
create table WHITE_LISTE
(
id_white_liste int not null,
numero int,
service_type varchar(254),
primary key (id_white_liste)
);
Bonjour!
Je viens à vous pour vous soumettre mon problème.
En effet je cherche à charger un fichier CSV dans ma base de données à travers le code suivant mais ça fonctionne pas
[code]
<form action= "<?php echo $_SERVER['PHP_SELF'];?>" method="post" enctype="application/x-www-form-urlencoded">
<fieldset style="width:600px">
<legend><b><h6>Précharger white liste</h6></b></legend>
<table width="80%" class="centre_tab2">
<tr><td align="right"><label for="services">Liste des services:</label></td>
<td><select name="SERVICES" id="services">
<option value="club20">CLUB20</option>
<option value="yabusiness">YA BUSINESS</option>
<option value="internetmobil">INTERNET MOBIL</option>
<option value="familleami">FAMILLE AMIS</option>
<option value="nexs">NEWS</option>
<option value="pharmacies">PHARMACIES</option>
</select></td></tr>
<tr><td align="right">Nom du Fichier</td>
<td><input type="file" name="file" /></td>
<td><input name="submit" type="submit" value="Charger" /></td></tr>
</table>
</fieldset>
<?php
$data = array();
function charge_numero($first)
{
global $data;
$data []= array(
'first' => $first);
//include ("connexion_bd.php");
// if ($_SESSION['login']!=NULL){
ini_set('display_errors','1');
//Inclusion de la classe mère
include ("SGBD.class.php");
/* Initialisation de la variable du SGBD correspondant */
$SQL = "MySQL";
// Inclusion de la classe fille du SGBD correspondant
include ($SQL.".SGBD.class.php");
/* Création d'un nouvel objet de la classe fille + lancement du constructeur */
$database = new $SQL('root', '', 'localhost', 'dbprojet');
// Connection à la base de données
$database->connect();
$database->requete("INSERT INTO WHITE_LISTE VALUES ('', $first , 'zszszzsx')");
}
$fichier=isset($_FILES["file"]["tmp_name"]);
if ( $fichier )
{
$dom = DOMDocument::load( $_FILES['file']['tmp_name'] );
$rows = $dom->getElementsByTagName( 'Row' );
$first_row = true;
foreach ($rows as $row)
{
if (!$first_row )
{
$first = "";
$index = 1;
$cells = $row->getElementsByTagName( 'Cell' );
foreach( $cells as $cell )
{
$ind = $cell->getAttribute( 'Index' );
if ( $ind != null ) $index = $ind;
if ( $index == 1 ) $first = $cell->nodeValue;
$index += 1;
}
charge_numero($first);
}
$first_row = false;
}
echo 'zzzzzzzzzzzzzzzzzzzzzzzz';
}
?>
</form>[/code]
Voici le code sql de ma table
[sql]/*==============================================================*/
/* Table : WHITE_LISTE */
/*==============================================================*/
create table WHITE_LISTE
(
id_white_liste int not null,
numero int,
service_type varchar(254),
primary key (id_white_liste)
);[/sql]