Note that there are some explanatory texts on larger screens.

plurals
  1. POColumn count doesn't match value count at row 1 - PHP Sub-Array
    primarykey
    data
    text
    <p>I am running into a problem inserting a subarray array values into a mysql table. I get the following error.</p> <p><strong>Column count doesn't match value count at row 1.</strong></p> <p>Not sure what I am doing wrong.</p> <p>Here is my table</p> <pre><code>CREATE TABLE IF NOT EXISTS `tbl_tourn_results` ( `fld_tr` char(10) NOT NULL, `fld_id_tr` char(5) NOT NULL, `fld_score` smallint(6) DEFAULT NULL, `fld_hole` smallint(6) DEFAULT NULL, `fld_T_Time` varchar(10) DEFAULT NULL, PRIMARY KEY (`fld_tourn_id_tr`,`fld_gPlayer_id_tr`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; </code></pre> <p>This is a array sample.</p> <pre><code>Array ( [0] =&gt; Array ( [fld_tr] =&gt; HONDA [fld_id_tr] =&gt; RoMcI [fld_score] =&gt; -12 [fldr_hole] =&gt; F ) [1] =&gt; Array ( [fld_tr] =&gt; HONDA [fld_id_tr] =&gt; TiWoo [fld_score] =&gt; -10 [fld_hole] =&gt; F ) [2] =&gt; Array ( [fld_tr] =&gt; HONDA [fld_id_tr] =&gt; TiWoo [fld_score] =&gt; -10 [fld_hole] =&gt; F ) [3] =&gt; Array ( [fld_tr] =&gt; HONDA [fld_id_tr] =&gt; TiWoo [fld_score] =&gt; -10 [fld_hole] =&gt; F ) ) </code></pre> <p>Here is the code I am using for inserting.</p> <pre><code>&lt;?php //Each 'sub-array' will become a row in the table foreach($result as $row){ $i = 0; //3 (not 4!) is the highest key in each sub-array while($i &lt;= 3){ //MySQL likes each value wrapped in apostrophes $row[$i] = '\'' . $row[$i] . '\''; $i++; } //Convert the sub-array into a comma-separated string $row = implode(",", $row); //MySQL query inserts the sub-array into a new row in the table mysql_query("INSERT INTO tbl_results (fld_tr, fld_id_tr, fld_score, fld_hole) VALUES({$row}) ") or die(mysql_error()); } ?&gt; </code></pre> <p>I get the following error. Column count doesn't match value count at row 1</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload