1
votes

I want import an input List in csv format, with separator (|), from an Textarea to my MySQL Database.

But it always failed, also if its in the correct format.

It comes the message: Error, 0 added successfully.

My format:

Thomas|Maier|5778011152|Bahnweg|232

Any one an Idea?

if(isset($_POST["base_name"]) && isset($_POST["new_entry"])) {
    $myList = preg_replace("/\r|\n/", "", preg_split("/$\R?^/m", $_POST["new_entry"]));
    foreach($myList as $info) $csv[] = explode($_POST["separator"], $info);

    $csvParams = $csv[0];
    array_shift($csv);

    $success = 0;
    $total = 0;

    foreach($csv as $info) {
        $sqlInsert = array_combine($csvParams, $info);
        $sqlInsert["base"] = $_POST["base_name"];
        $sqlInsert["info"] = "unbenutzt";

        $p = softwareInsertArray($softwareSqlLink, $sqlInsert, "person");
        if($p) $success++;
        $total++;
    }

    $q = softwareRunQuery($softwareSqlLink, false, "INSERT INTO statistics (`key`, `val`) VALUES ('".$_POST["base_name"]."|profit', '0');");
}

if(isset($total)) {
    if($total == $success && $total > 0 && $q) {
        $alert = array("type" => "success", "header" => "Erfolgreich!", "text" => "Success.");
        softwareSqlLog($softwareSqlLink, "person", array("status" => 1, "info" => array("base" => $_POST["base_name"], "text" => $success." person added successfully")));
    } else {
        $alert = array("type" => "danger", "header" => "Fehler!", "text" => $success."/".$total." sucess.");
        softwareSqlLog($softwareSqlLink, "person", array("status" => 0, "info" => array("base" => $_POST["base_name"], "text" => $success."/".$total." added.")));
    }
}

softwareInsertArray code: pastebin.com/raw/vUnQTpxU

1

1 Answers

0
votes

Do you just want to replace the pipes with commas? IE SELECT replace('Thomas|Maier|5778011152|Bahnweg|232','|', ',' )