Jump to content

Column count doesn't match value count at row 1


lared

Recommended Posts

I am new playing with php and mysql and don't know how to fix this problem shocking me for two days long and really don't found what's

the matter so if there is anybody who knows how to fix this your

help would be appreciated.

 

Have this mysql, myisam data base:

 

Field                Type            Collation    Null  Default 

Id                     int(10)                 No    auto_increment

Fecha               date                 No

Referencia         mediumint(20)               No

Descripcion            varchar(25) latin1_spanish_ci  No

Monto               float                 No

Saldo               float                 No

 

Indexes: Documentation Keyname Type Cardinality Field

          PRIMARY PRIMARY 0    Edit         Id

 

MySQL client version: 4.1.22

 

Have a file.txt like this:

 

'';09/02/2009;03761407654;DEPOSITO    03761407654              ;                    +50,00;                      644,00;

'';09/02/2009;03376143599;DEPOSITO    03376143599              ;                    +50,00;                      694,00;

'';09/02/2009;00376140765;DEPOSITO    00376140765              ;                    +50,00;                      744,00;

'';09/02/2009;00376140764;DEPOSITO    00376140764              ;                    +50,00;                      794,00;

'';09/02/2009;00037614762;DEPOSITO    00037614762              ;                    +50,00;                      844,00;

'';09/02/2009;00376140761;DEPOSITO    00376140761              ;                    +50,00;                      894,00;

 

Run this script:

 

<?php

$host="localhost";

$username=" ";

$password=" ";

$db_name=" "; 

 

 

mysql_connect("$host", "$username", "$password")or die("cannot connect to server");

mysql_select_db("$db_name")or die("cannot select DB");

 

$fcontents = file ('./file.txt');

 

  for($i=0; $i<sizeof($fcontents); $i++) {

      $line = trim($fcontents[$i]);

      $arr = explode("\;", $line);

     

   

      $sql = "insert into TABLE_NAME (Id, Fecha, Referencia, Descripcion, Monto, Saldo) values ('".

                  implode("';'", $arr) ."')";

              mysql_query($sql);

      echo $sql ."<br>\n";

      if(mysql_error()) {

        echo mysql_error() ."<br>\n";

      }

}

mysql_close;

 

?>

 

And mysql returns this:

 

insert into J296950733 (Id, Fecha, Referencia, Descripcion, Monto, Saldo) values (';09/02/2009;03761407654;DEPOSITO 03761407654 ; +50,00; 644,00;')

Column count doesn't match value count at row 1

insert into J296950733 (Id, Fecha, Referencia, Descripcion, Monto, Saldo) values (';09/02/2009;03376143599;DEPOSITO 03376143599 ; +50,00; 694,00;')

Column count doesn't match value count at row 1

insert into J296950733 (Id, Fecha, Referencia, Descripcion, Monto, Saldo) values (';09/02/2009;00376140765;DEPOSITO 00376140765 ; +50,00; 744,00;')

Column count doesn't match value count at row 1

insert into J296950733 (Id, Fecha, Referencia, Descripcion, Monto, Saldo) values (';09/02/2009;00376140764;DEPOSITO 00376140764 ; +50,00; 794,00;')

Column count doesn't match value count at row 1

insert into J296950733 (Id, Fecha, Referencia, Descripcion, Monto, Saldo) values (';09/02/2009;00037614762;DEPOSITO 00037614762 ; +50,00; 844,00;')

Column count doesn't match value count at row 1

insert into J296950733 (Id, Fecha, Referencia, Descripcion, Monto, Saldo) values (';09/02/2009;00376140761;DEPOSITO 00376140761 ; +50,00; 894,00;')

Column count doesn't match value count at row 1

 

Thanks you!

Link to comment
Share on other sites

change

$sql = "insert into TABLE_NAME (Id, Fecha, Referencia, Descripcion, Monto, Saldo) values ('".
                  implode("';'", $arr) ."')";

to

$sql = "insert into TABLE_NAME (Id, Fecha, Referencia, Descripcion, Monto, Saldo) values ('".
                  implode("','", $arr) ."')";

change ; to , in implode function

and

$arr = explode("\;", $line); 

to

$arr = explode(";", $line); 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.