Import csv file

Questions related to customising nuBuilder Forte with Javascript or PHP.

Re: Import csv file

Postby kev1n » Thu Jul 16, 2020 6:45 pm

There are syntax errors in import.php (use https://phpcodechecker.com/ to check for errors).

I think it should be like this:

Code: Select all
<?php
//import.php
if (isset($_POST["customerName"])) {
    $connect = new PDO("mysql:host=localhost;dbname=nubuilder4", "root", "");
    $customerName = $_POST["customerName"];
    $customerPhone = $_POST["customerPhone"];
    $customerEmail = $_POST["customerEmail"];
    $customerAddress = $_POST["customerAddress"];
    $appointmentDate = $_POST["appointmentDate"];

    for ($count = 0;$count < count($customerName);$count++) {
        $query .= "
  INSERT INTO tbl_Customers(customerName, customerPhone, customerEmail, customerAddress, appointmentDate)
  VALUES ('" . $customerName[$count] . "', '" . $customerPhone[$count] . "', '" . $ccustomerEmail[$count] . "', '" . $customerAddress[$count] . "', '" . $appointmentDate[$count] . "');

  ";
    }
    $statement = $connect->prepare($query);
    $statement->execute();
}

?>
kev1n
 
Posts: 1038
Joined: Mon Oct 15, 2018 2:13 am

Re: Import csv file

Postby hiramalik » Thu Jul 16, 2020 6:48 pm

You are a saviour..
Thank you sooooo much :) :D
hiramalik
 
Posts: 15
Joined: Wed Jul 15, 2020 8:04 pm

Re: Import csv file

Postby hiramalik » Fri Jul 17, 2020 8:34 pm

Here again with another issue. Now that everything else works fine, file is being imported thrice. For example if I have imported 3 rows. Each row will be imported thrice making total of 9 rows. Please help..
hiramalik
 
Posts: 15
Joined: Wed Jul 15, 2020 8:04 pm

Re: Import csv file

Postby kev1n » Sun Jul 19, 2020 6:16 pm

Replace this line:

Code: Select all
$(document).on('click', '#import_data', function(){


with this:

Code: Select all
$(document).off('click', '#import_data').on('click', '#import_data', function(){
kev1n
 
Posts: 1038
Joined: Mon Oct 15, 2018 2:13 am

Re: Import csv file

Postby hiramalik » Wed Jul 22, 2020 4:25 am

Thanks Kev1n :D
hiramalik
 
Posts: 15
Joined: Wed Jul 15, 2020 8:04 pm

Re: Import csv file

Postby admin » Tue Oct 06, 2020 9:55 am

There is now a simple CSV Import/Export available in nuBuilder Forte.

https://forums.nubuilder.com/viewtopic.php?f=18&t=10583


Steven
admin
Site Admin
 
Posts: 3372
Joined: Mon Jun 15, 2009 9:53 am

Re: Import csv file

Postby kev1n » Wed Oct 14, 2020 3:12 pm

Cool - it's a nice addition!
kev1n
 
Posts: 1038
Joined: Mon Oct 15, 2018 2:13 am

Re: Import csv file

Postby admin » Thu Oct 15, 2020 3:56 am

Thanks.

I used some of your code.


Steven
admin
Site Admin
 
Posts: 3372
Joined: Mon Jun 15, 2009 9:53 am

Previous

Return to Custom Code