Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Import csv file

Questions related to customising nuBuilder Forte with JavaScript or PHP.
kev1n
nuBuilder Team
Posts: 4305
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 446 times
Contact:

Re: Import csv file

Unread post by kev1n »

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();
}

?>
hiramalik
Posts: 20
Joined: Wed Jul 15, 2020 12:34 pm

Re: Import csv file

Unread post by hiramalik »

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

Re: Import csv file

Unread post by hiramalik »

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..
kev1n
nuBuilder Team
Posts: 4305
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 446 times
Contact:

Re: Import csv file

Unread post by kev1n »

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(){
hiramalik
Posts: 20
Joined: Wed Jul 15, 2020 12:34 pm

Re: Import csv file

Unread post by hiramalik »

Thanks Kev1n :D
admin
Site Admin
Posts: 2815
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: Import csv file

Unread post by admin »

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

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


Steven
kev1n
nuBuilder Team
Posts: 4305
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 446 times
Contact:

Re: Import csv file

Unread post by kev1n »

Cool - it's a nice addition!
admin
Site Admin
Posts: 2815
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: Import csv file

Unread post by admin »

Thanks.

I used some of your code.


Steven
Post Reply