insert CSV in mySql problem

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default insert CSV in mySql problem

    Hi,

    The script below add twice the same line from de CSV in the DB,
    Is there something I am missing...

    -------
    $link = mysql_connect("localhost","","");
    $selection = mysql_select_db("table", $link);
    $line = array();
    $fclients = fopen("file.csv","r");
    while ($line = fgetcsv($fclients, 1500, ",")) {
    $name_cie = addslashes(trim($line[0]));
    $adress = addslashes(trim($line[1]));
    $tel = addslashes(trim($line[3]));
    $fax = addslashes(trim($line[4]));
    $mail = addslashes(trim($line[5]));
    $name = addslashes(trim($line[6]));
    $title = addslashes(trim($line[7]));
    $site = addslashes(trim($line[8]));
    }
    $request = "INSERT INTO contact
    (name_cie,adress,tel,fax,mail,name,title,site,desc ription)";
    $request .= "VALUES
    ('$name_cie','$adresse','$tel','$fax','$mail','$na me','$title','$site','$des
    cription')";
    $result = mysql_query($request) or DIE("Error: " . mysql_error()) ;
    -------

    Any help would be appreciated.

    R. Sauve



    Richard Sauve Guest

  2. Similar Questions and Discussions

    1. Problem With Insert into MySQL DB using VB.Net 2005
      Hello everyone, I am having a issue inserting values into a MYSQL table, and for the life of me, I can figure out why. I know the connection is...
    2. MySql insert question.
      hi all thanks again for all th direction you guys have given me in the past and hopefully now.. i have a partial backend done for uploading...
    3. id after insert in MySQL
      I'm trying to obtain the id of an INSERTed MySQL record (which is set as AUTO INCREMENT in my table btw). I believe the php function is...
    4. insert combobox into MySQL db
      I cant seem to figre this out nor can i find an example of it: how to insert the value of the combox to the dB. this is what I have got so far: ...
    5. php problem array insert into mysql
      I am having trouble inserting my array into mysql db. Everything else is working except for the insert into the DB. I've read through many of the...
  3. #2

    Default Re: insert CSV in mySql problem

    Richard Sauve wrote:
    > Hi,
    >
    > The script below add twice the same line from de CSV in the DB,
    > Is there something I am missing...
    >
    > -------
    > $link = mysql_connect("localhost","","");
    > $selection = mysql_select_db("table", $link);
    > $line = array();
    > $fclients = fopen("file.csv","r");
    > while ($line = fgetcsv($fclients, 1500, ",")) {
    > $name_cie = addslashes(trim($line[0]));
    > $adress = addslashes(trim($line[1]));
    > $tel = addslashes(trim($line[3]));
    > $fax = addslashes(trim($line[4]));
    > $mail = addslashes(trim($line[5]));
    > $name = addslashes(trim($line[6]));
    > $title = addslashes(trim($line[7]));
    > $site = addslashes(trim($line[8]));
    > }
    > $request = "INSERT INTO contact
    > (name_cie,adress,tel,fax,mail,name,title,site,desc ription)";
    > $request .= "VALUES
    > ('$name_cie','$adresse','$tel','$fax','$mail','$na me','$title','$site','$des
    > cription')";
    > $result = mysql_query($request) or DIE("Error: " . mysql_error()) ;
    > -------
    >
    > Any help would be appreciated.
    >
    > R. Sauve
    >
    >
    >
    If its a simple csv file, why not just use the MySQL command "IMPORT" to
    import it?
    Milambar Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139