CSV format data input to mysql with separator
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
php mysql mysqli export-to-csv
add a comment |
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
php mysql mysqli export-to-csv
add a comment |
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
php mysql mysqli export-to-csv
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
php mysql mysqli export-to-csv
php mysql mysqli export-to-csv
edited Jan 2 at 8:44
Madhuri Patel
873621
873621
asked Jan 2 at 8:26
berryleeberrylee
62
62
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Do you just want to replace the pipes with commas?
IE SELECT replace('Thomas|Maier|5778011152|Bahnweg|232','|', ',' )
Also tried with commas. But if i leave the seperator input empty and add 5 lines in textarea infos added, but without infos, maybe because there are more DB columns not just : Name, Surname, Phone, Street,Number ?
– berrylee
Jan 2 at 9:03
The above solution would just return a string like this: 'Thomas, Maier, 5778011152, Bahnweg, 232' If each of these are to be treated as separate values that each correspond to another column we'll need to craft it a bit differently. Do you need to seperate each piece of your string and format an insert query to store each piece in a particular column? IE: 'Thomas' = [FirstName] 'Maier' = [LastName] etc?
– Christi G
Jan 2 at 9:39
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54003247%2fcsv-format-data-input-to-mysql-with-separator%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Do you just want to replace the pipes with commas?
IE SELECT replace('Thomas|Maier|5778011152|Bahnweg|232','|', ',' )
Also tried with commas. But if i leave the seperator input empty and add 5 lines in textarea infos added, but without infos, maybe because there are more DB columns not just : Name, Surname, Phone, Street,Number ?
– berrylee
Jan 2 at 9:03
The above solution would just return a string like this: 'Thomas, Maier, 5778011152, Bahnweg, 232' If each of these are to be treated as separate values that each correspond to another column we'll need to craft it a bit differently. Do you need to seperate each piece of your string and format an insert query to store each piece in a particular column? IE: 'Thomas' = [FirstName] 'Maier' = [LastName] etc?
– Christi G
Jan 2 at 9:39
add a comment |
Do you just want to replace the pipes with commas?
IE SELECT replace('Thomas|Maier|5778011152|Bahnweg|232','|', ',' )
Also tried with commas. But if i leave the seperator input empty and add 5 lines in textarea infos added, but without infos, maybe because there are more DB columns not just : Name, Surname, Phone, Street,Number ?
– berrylee
Jan 2 at 9:03
The above solution would just return a string like this: 'Thomas, Maier, 5778011152, Bahnweg, 232' If each of these are to be treated as separate values that each correspond to another column we'll need to craft it a bit differently. Do you need to seperate each piece of your string and format an insert query to store each piece in a particular column? IE: 'Thomas' = [FirstName] 'Maier' = [LastName] etc?
– Christi G
Jan 2 at 9:39
add a comment |
Do you just want to replace the pipes with commas?
IE SELECT replace('Thomas|Maier|5778011152|Bahnweg|232','|', ',' )
Do you just want to replace the pipes with commas?
IE SELECT replace('Thomas|Maier|5778011152|Bahnweg|232','|', ',' )
answered Jan 2 at 8:54
Christi GChristi G
465
465
Also tried with commas. But if i leave the seperator input empty and add 5 lines in textarea infos added, but without infos, maybe because there are more DB columns not just : Name, Surname, Phone, Street,Number ?
– berrylee
Jan 2 at 9:03
The above solution would just return a string like this: 'Thomas, Maier, 5778011152, Bahnweg, 232' If each of these are to be treated as separate values that each correspond to another column we'll need to craft it a bit differently. Do you need to seperate each piece of your string and format an insert query to store each piece in a particular column? IE: 'Thomas' = [FirstName] 'Maier' = [LastName] etc?
– Christi G
Jan 2 at 9:39
add a comment |
Also tried with commas. But if i leave the seperator input empty and add 5 lines in textarea infos added, but without infos, maybe because there are more DB columns not just : Name, Surname, Phone, Street,Number ?
– berrylee
Jan 2 at 9:03
The above solution would just return a string like this: 'Thomas, Maier, 5778011152, Bahnweg, 232' If each of these are to be treated as separate values that each correspond to another column we'll need to craft it a bit differently. Do you need to seperate each piece of your string and format an insert query to store each piece in a particular column? IE: 'Thomas' = [FirstName] 'Maier' = [LastName] etc?
– Christi G
Jan 2 at 9:39
Also tried with commas. But if i leave the seperator input empty and add 5 lines in textarea infos added, but without infos, maybe because there are more DB columns not just : Name, Surname, Phone, Street,Number ?
– berrylee
Jan 2 at 9:03
Also tried with commas. But if i leave the seperator input empty and add 5 lines in textarea infos added, but without infos, maybe because there are more DB columns not just : Name, Surname, Phone, Street,Number ?
– berrylee
Jan 2 at 9:03
The above solution would just return a string like this: 'Thomas, Maier, 5778011152, Bahnweg, 232' If each of these are to be treated as separate values that each correspond to another column we'll need to craft it a bit differently. Do you need to seperate each piece of your string and format an insert query to store each piece in a particular column? IE: 'Thomas' = [FirstName] 'Maier' = [LastName] etc?
– Christi G
Jan 2 at 9:39
The above solution would just return a string like this: 'Thomas, Maier, 5778011152, Bahnweg, 232' If each of these are to be treated as separate values that each correspond to another column we'll need to craft it a bit differently. Do you need to seperate each piece of your string and format an insert query to store each piece in a particular column? IE: 'Thomas' = [FirstName] 'Maier' = [LastName] etc?
– Christi G
Jan 2 at 9:39
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54003247%2fcsv-format-data-input-to-mysql-with-separator%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown