Ver Mensaje Individual
  #1 (permalink)  
Antiguo 12/06/2013, 01:02
Avatar de hellsingstq
hellsingstq
 
Fecha de Ingreso: junio-2013
Ubicación: Madrid
Mensajes: 12
Antigüedad: 11 años, 8 meses
Puntos: 0
Exclamación Fallo al cargar archivos en BD

Buenas! Tengo el siguiente problema, estoy intentando cargar un archivo por PHP en una base de datos de MySQL, el Script es el siguiente:

$server = 'localhost';
$user = 'xxx';
$passwort = 'xxx';
$database = 'my_db';
$file = (isset($_FILES['file']) ? $_FILES['file'] : NULL);
$verbindung = mysql_connect($server, $user, $passwort) or die ("Keine Verbindung möglich");

if($verbindung){
$db= mysql_select_db($database) or die ("Die Datenbank existiert nicht");
$sql = "LOAD DATA INFILE '$file'
INTO TABLE students
FIELDS TERMINATED BY ','
ENCLOSED BY ''
LINES TERMINATED BY '\n' ";
echo mysql_error();
if($sql){
$ergebnis = mysql_query($sql);
if($ergebnis){
echo "Datas written in table $ergebnis . <br>";

}
else
{
echo "Failed to write Datas into table";
}

echo "<table border='1'>";
echo "<tr>
<th>Number</th>
<th>Name</th>
<th>Surname</th>
<th>Teacher</th>
<th>Classname</th> </tr>";
$select_data = "Select * from `students`";
$select_data = mysql_query ("Select * from `students`");
while($row = mysql_fetch_row($select_data))
{
// Print out the contents of each row into a table
echo "<tr><td>";
echo $row[0];
echo "</td><td>";
echo $row[1];
echo "</td><td>";
echo $row[2];
echo "</td><td>";
echo $row[3];
echo "</td><td>";
echo $row[4];
echo "</td></tr>";
}

echo "</table>";
}

}
mysql_close($verbindung);
?>


El codigo de la pagina web en la que esta el formulario es el siguiente:


<form action=csvimport07.php method="post" enctype="multipart/form-data">
<table>
<tr><td>Select the file to import:</td><td><input name="csv" type="file" id="csv"/>
</table>
<i>*Note: The CSV file must have the following format: ;Name;Surname;y/n(is he/she a teacher?);Classname;</i><br><br>
<input type="Submit" name="Submit" value="Submit" />
</form>


Y el error que me sale una vez selecciono el archivo y lo subo es el siguiente:

Failed to write Datas into table

Agradeceria que me echarais una mano diciendome los fallos que tengo puesto que llevo dandole vueltas una semana al script y no encuentro solucion...Gracias!