Hallo Leute,
habe folgenden PHP Code geschrieben:
Bekomme folgende Fehlermeldung, womit ich nicht viel anfangen kan:
Als Beispiel CSV gibt es folgende Zeilen:
Ich hoffe ihr könnt mir weiter helfen.
Lg
Tron36
habe folgenden PHP Code geschrieben:
PHP:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "studentadvice";
// Create connection
$dbConnection = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($dbConnection->connect_error) {
die("Connection failed: " . $dbConnection->connect_error);
}
$columns =array();
$handle = fopen("pseudonoten.csv", "r");
$firstLine = true;
while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) {
if($firstLine){
$firstLine = false;
} elseif (!$firstLine) {
$SQLquery = buildSQLInsertString($data, "pseudonoten (ID, Unit, Semester, Note, BNF)");
$result = $dbConnection->query($SQLquery);
if ($result === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $result . "<br>" . $conn->error;
}
}
}
fclose($fileHandle);
function buildSQLInsertString($rowContent, $table) {
return "INSERT INTO " . $table . " VALUES ('" . $rowContent[0] . "', '" . $rowContent[1] . "', '". $rowContent[2] . "', '".$rowContent[3]."', '".$rowContent[4]."')";
}
?>
Bekomme folgende Fehlermeldung, womit ich nicht viel anfangen kan:
Code:
Notice: Undefined offset: 1 in D:\xampp\htdocs\uni\csvimport\importCSV.php on line 38
Notice: Undefined offset: 2 in D:\xampp\htdocs\uni\csvimport\importCSV.php on line 38
Notice: Undefined offset: 3 in D:\xampp\htdocs\uni\csvimport\importCSV.php on line 38
Notice: Undefined offset: 4 in D:\xampp\htdocs\uni\csvimport\importCSV.php on line 38
Notice: Undefined variable: conn in D:\xampp\htdocs\uni\csvimport\importCSV.php on line 30
Notice: Trying to get property 'error' of non-object in D:\xampp\htdocs\uni\csvimport\importCSV.php on line 30
Error:
Als Beispiel CSV gibt es folgende Zeilen:
Code:
ID,Unit,Semester,Note,BNF
1417;143014;3997;5,0;5
Ich hoffe ihr könnt mir weiter helfen.
Lg
Tron36