I am having an issue with my form submission. I have read all related posts but none of them really solved my issue. I have triple checked the number of fields and values and they match 100%. I would really appreciate if someone can help me out.
This is the message I get: Issue with DB query. “Column count doesn’t match value count at row 1”
$table="bayi_basvuru";
$sql="INSERT INTO bayi_basvuru(
company_name,
city,
operation_area,
authorized_person,
authorized_email,
authorized_tel,
company_url,
created_at
)VALUES(
'{$_POST["company_name"]}',
'{$_POST["city"]}', ----------> This is a select field
'{$_POST["operation_area"]}' ----------> This is also a select field
'{$_POST["authorized_person"]}',
'{$_POST["authorized_email"]}',
'{$_POST["authorized_tel"]}',
'{$_POST["company_url"]}',
NOW()
)";
}
Your example is missing a comma. I don’t know if it was lost when the code was pasted into the forum or if is missing in the original but it needs to be,
Another example of why @r937 's oft suggested “leading comma” format is a good idea eg.
$sql="INSERT INTO bayi_basvuru(
company_name
, city
, operation_area
, authorized_person
, authorized_email
, authorized_tel
, company_url
, created_at
)VALUES(
'{$_POST["company_name"]}'
, '{$_POST["city"]}' ----------> This is a select field
, '{$_POST["operation_area"]}' ----------> This is also a select field
'{$_POST["authorized_person"]}'
, '{$_POST["authorized_email"]}'
, '{$_POST["authorized_tel"]}'
, '{$_POST["company_url"]}'
, NOW()
)";
}
[quote=“Mittineague, post:5, topic:113959”]
Another example of why @r937 's oft suggested “leading comma” format is a good idea [/quote]
thank you so much for the support
i am still deeply wounded by losing the overall battle with sitepoint’s book editor regarding coding style, which resulted in all the code samples in my book being butchered…
… but i am happy to say that i won the fight over the leading comma, even despite disagreement by Joe Celko, technical reviewer of the book
it remains my steadfast belief that any coder, of any computer language, who has ever used a text editor to perform operations like deleting an entire line of code, will, once the advantages are seen, gladly embrace the leading comma convention
Thanks for the warning. I have just started learning PHP and never used prepared statements before. Would you be able to recommend any tutorials on this feature?