lared Posted February 19, 2009 Share Posted February 19, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/145901-column-count-doesnt-match-value-count-at-row-1/ Share on other sites More sharing options...
sasa Posted February 19, 2009 Share Posted February 19, 2009 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); Quote Link to comment https://forums.phpfreaks.com/topic/145901-column-count-doesnt-match-value-count-at-row-1/#findComment-766026 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.