SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Insert syntax

  1. #1
    SitePoint Member
    Join Date
    Nov 2005
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Insert syntax

    I've got part way through a script to write an csv to mysql. I am getting the "column count doesn't match value count at row 1" error. I am think it might because some of the fields are paragraphs of text. So I escaped the puncuation thinking that it might interpreting those fields as several fields, but it didn't help.
    The only thing I can think of is delineating the fields and columns in the command - but I can't get that syntax right either. And I'm not sure it would help. Would the string types set for the mySql fields influence this. That's all I can think of since the columns and fields have/are same number, order and names in the csv and db.
    here's the snippet:
    for($i=0; $i<sizeof($fcontents); $i++) {
    $line = trim($fcontents[$i], ',');
    $arr = explode(",", $line);


    $sql = "insert into my_table values ('".
    implode("','", $arr) ."')";

    Soon I might cry so I'd love any help that anyone might feel like offering.

  2. #2
    SitePoint Addict
    Join Date
    Sep 2004
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Show me a few lines from your csv file and show me the structure of the mysql table you want to insert the data from the csv in


Bookmarks

Posting Permissions

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