nightstalker — 2010-02-12T00:25:00-05:00 — #1
I have an insert statement like this:
insert into table_name (colm1, colm2, colm3, colm5) VALUES ('','','','');
But it gives me the following error:
Column count doesn't match value count at row 1
After googling around a bit, It seems that I must include all columns from the table in the insert. Is that correct? So I cannot omit colm4, even if it is going to be null?
Thanks for any feedback
dan_grossman — 2010-02-12T00:41:58-05:00 — #2
No, you can omit columns. If that was the real query it would work fine. I bet it's some minor syntax error you're overlooking, a typo.
Share the real query and you can get a fresh set of eyes on it.
nightstalker — 2010-02-12T03:56:39-05:00 — #3
ah ok. That would be fantastic. As fresh eyes might see something I do not.
here is the query:
$qry = "INSERT INTO `TableName` (`business_name`, `contact`, `tel_num`, `fax_num`,`email`, `cell_num`, `address`, ";
$qry .= "`postal_address`, `business_mobile`, `business_email`, `business_fax`, `URL`, `accounts_contact`, `accounts_email`, ";
$qry .= "`short_name`, `credit`, `vat_num`, `supplier_type_id`) VALUES ('$TradingName', '$contact', ";
$qry .= "'$Tell', '$Fax', '$Email', '$Cell', '$address', ";
$qry .= "'$post_address', '$BusCell', '$BusEmail', '$BusFax', '$BusUrl', ";
$qry .= "'$contactDetails', '$ContactEmail', '$FinName', '$FinTurnover', '$VAT', ";
$qry .= "$rdoCompany)";
Thanks for the help
dr_john — 2010-02-12T05:09:10-05:00 — #4
Possibly wrong, but the last value given is
$qry .= "$rdoCompany)";
should it be
$qry .= " '$rdoCompany' )";
nightstalker — 2010-02-12T05:22:19-05:00 — #5
I can try that, but thought it is not needed as it is of type int. Will give it a shot tho and let you guys know. But I am thinking its a comma or something missing somewhere as to way its complaining about columns, etc
dan_grossman — 2010-02-12T05:59:31-05:00 — #6
That query is fine. I created that table and ran it, no error.
Which means that one or more of those variables contains a value with unescaped single quotes. You need to call mysql_real_escape_string on each of those values before putting them in the query.
nightstalker — 2010-02-12T06:32:26-05:00 — #7
ah ok. Thanks a lot for the help. I will do that. Could be that one variable is like this:
$eg = "$val1, $val2, $val3";
So I will just split that with $val1.','.$val2 etc
dan_grossman — 2010-02-12T06:46:04-05:00 — #8
I don't see how changing the way you concatenate strings will help?
nightstalker — 2010-02-12T09:32:16-05:00 — #9
Just to make sure I have all my bases covered.
dan_grossman — 2010-02-12T10:38:41-05:00 — #10
<~ Honestly confused.
How can changing the way you concatenate strings help or hurt anything?
nightstalker — 2010-02-13T02:21:17-05:00 — #11
lol. I dnt no. I was thinking maybe the commas is being read as 3 values instead of just one. Just an idea. I do not know PHP that well.
nightstalker — 2010-02-14T13:45:30-05:00 — #12
Thanks again for the help. The problem was exactly as you said. I found the rouge ' and eradicated it. lol.
Thanks all for the help
dan_grossman — 2010-02-14T14:20:37-05:00 — #13