Results 1 to 14 of 14
  1. #1
    Join Date
    Oct 2009
    Posts
    6

    Unanswered: Help with adding products to database

    I am a newbie to sql so here is what I am trying to do, can somebody please help me.
    I have an excel spreadsheet with 4 columns of products as listed below
    1) Product Name
    2) Description
    3) Price
    4) Link
    I am using myphpadmin and I created 4 tables with the names listed above. I converted the excel file to csv and then I imported it to my database but I cannot make it to show in the right tables. Can someone please help me by telling how to do it from scratch. I do not know if when I created the tables if I used the right format for each table. If this was your project how would you create the tables and how would you upload the files (step by step instructions would be very helpful). Thank you in advance.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    there should be only one table, not four

    CREATE TABLE products
    ( Name VARCHAR(55)
    , Description VARCHAR(55)
    , Price DECIMAL(7,2)
    , Link VARCHAR(55)
    );

    then look up the LOAD DATA INFILE command to load your csv directly into this table
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Oct 2009
    Posts
    6
    I want to thank you for taking the time to help me. I went ahead and created the tables but when I try to import the csv file into my database, all the information is only copied into the Name field. The other tables all have NULL on them. I tried every possible way to import it but I cannot import each column to the tables that I created. This is exactly what I am doing to import the csv file.
    1) I click on the IMPORT tab in myphpadmin
    2) I locate the file in my hard drive and then I choose CSV USING LOAD DATA option. I leave the OPTION field the way they are because I do not know what they are for and then I press GO.
    3) I get a message that it was successful but when I check my tables, only the NAME table has all the data entered on it and the other tables have NULL on them.

    Please help. Thanks in advance.
    Last edited by 915855; 10-07-09 at 16:11.

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    there should be only one table, not four
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Oct 2009
    Posts
    6
    Sorry, there is one table and it has 4 fields. Can you please tell me what I am doing wrong when uploading the file.Thanks

  6. #6
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    Assuming your using data load command then you need to look at the field separator clause.

  7. #7
    Join Date
    Oct 2009
    Posts
    6
    Can you tell me how I would do that.Thanks

  8. #8
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    You'll need to give us what you initially used to load the data plus the first few lines of the data. It would help if we had the table definition to.

  9. #9
    Join Date
    Oct 2009
    Posts
    6
    I am a newbie and you totally lost me with your question but I will try to answer it. I created the data in excel and saved it as CSV. The data has 4 columns as follows:
    Column 1 = Name
    Column 2 = Description
    Column 3 = Price
    Column 4 = Link

    The table definition is the same as the one given to me by r937 which is:

    CREATE TABLE products
    ( Name VARCHAR(55)
    , Description VARCHAR(55)
    , Price DECIMAL(7,2)
    , Link VARCHAR(55)
    );

    Any help I will greatly appreciate it. Thanks.

  10. #10
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    How did you import the csv file into the database?
    Is there an option to set the field separator to a comma?

  11. #11
    Join Date
    Oct 2009
    Posts
    6
    I did not set an option. Can you please tell me step by step instructions on how to fill out these fields. Thanks.

  12. #12
    Join Date
    Oct 2009
    Posts
    8

    Import csv file using phpMyAdmin

    -Create the database first.
    -Click on the database name.
    -Click the import tab.
    -Browse and find the csv file you want to import- using r937 file format
    -Click go.

    This may help.

  13. #13
    Join Date
    Oct 2009
    Posts
    8

    Import file to database using myphpadmin

    CREATE TABLE products
    ( Name VARCHAR(55)
    , Description VARCHAR(55)
    , Price DECIMAL(7,2)
    , Link VARCHAR(55)
    );

    INSERT INTO `products`(`Name`,`Description`,`Price`,`Link`) VALUES ('Corn','Yellow Corn','$5.00','www.light.com'),
    ('Pepper','Hot Pepper','10.00','www.whatever.com');

    Additional info.

  14. #14
    Join Date
    Oct 2009
    Posts
    1
    I agree this is exactly for the csv file:
    1) I click on the IMPORT tab in myphpadmin
    2) I locate the file in my hard drive and then I choose CSV USING LOAD DATA option. I leave the OPTION field the way they are because I do not know what they are for and then I press GO.
    3) I get a message that it was successful.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •