MySql insert question

Hey guys

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

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.

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

Possibly wrong, but the last value given is
$qry .= “$rdoCompany)”;

should it be
$qry .= " ‘$rdoCompany’ )";
?

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

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.

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

Thanks again

I don’t see how changing the way you concatenate strings will help?

Just to make sure I have all my bases covered.

<~ Honestly confused.

How can changing the way you concatenate strings help or hurt anything?

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.

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

http://php.net/manual/en/function.mysql-real-escape-string.php