Unknown column 'emp_city' in 'field list' - ARGH
Posted: Sun Apr 17, 2011 10:15 am
I'm using a function to write a query for a largish form:
function mysql_insert_array($table, $data) {
foreach ($data as $field=>$value)
if ($key!="submit" AND $key!="disc_accept"){ {
$fields[] = $field;
$values[] = "'" . mysql_real_escape_string($value) . "'";
} }
$field_list = join(',', $fields);
$value_list = join(', ', $values);
$query = "INSERT INTO " . $table . " (" . $field_list . ") VALUES (" . $value_list . ")";
return $query;
}
$sqlDATA = mysql_insert_array(enr_group, $data);
// Do insert statement.
mysql_query("$sqlDATA") or die(mysql_error());
If I echo the output of $sqlDATA, the query looks correct (crap entered into form for testing right now).
INSERT INTO enr_group (date_effective_m,date_effective_d,date_effective_y,emp_gp_name,emp_fein,emp_street_addressa,emp_street_addressb,emp_city,emp_state,emp_postal,emp_country,trvl_fac,emp_operations,emp_carrier,emp_plan_num,emp_eligible_members,omt_mandatory,incentive_details,include_all,add_details,prim_fname,prim_lname,prim_street,prim_street2,prim_city,prim_state,prim_postal,prim_country,prim_email,prim_phone1,prim_phone2,prim_phone3,prim_fax1,prim_fax2,prim_fax3,disc_accept) VALUES ('2', '3', '2011', 'asdfasdf', 'asdf', 'asdf', 'asdf', 'asdf', 'asdg', 'asdg', 'United States', 'Yes', 'asdg', 'asdg', 'asdg', 'asdg', 'Mandatory', 'asdg', 'Yes', 'asdg', 'asdg', 'asdg', 'sadg', 'asdg', 'asdg', 'asdg', '12121', 'American Samoa', 'asdf@asdf.com', '121', '111', '1111', '343', '333', '3333', 'Yes');
When all this is run, I get "Unknown column 'emp_city' in 'field list' "
The form field names EXACTLY match what's in the database. The field is in there. I wrote the form first, then a chunk of code to create the table using the exact field names entered into the form to prevent typos. And double checking for the 1597th time, yes, "emp_city" IS in there and all the other field names are correct and the number of fields match the database table as well...
Banging my head against the wall on this. Any ideas? Or do I need to drink some more coffee and take a walk?
function mysql_insert_array($table, $data) {
foreach ($data as $field=>$value)
if ($key!="submit" AND $key!="disc_accept"){ {
$fields[] = $field;
$values[] = "'" . mysql_real_escape_string($value) . "'";
} }
$field_list = join(',', $fields);
$value_list = join(', ', $values);
$query = "INSERT INTO " . $table . " (" . $field_list . ") VALUES (" . $value_list . ")";
return $query;
}
$sqlDATA = mysql_insert_array(enr_group, $data);
// Do insert statement.
mysql_query("$sqlDATA") or die(mysql_error());
If I echo the output of $sqlDATA, the query looks correct (crap entered into form for testing right now).
INSERT INTO enr_group (date_effective_m,date_effective_d,date_effective_y,emp_gp_name,emp_fein,emp_street_addressa,emp_street_addressb,emp_city,emp_state,emp_postal,emp_country,trvl_fac,emp_operations,emp_carrier,emp_plan_num,emp_eligible_members,omt_mandatory,incentive_details,include_all,add_details,prim_fname,prim_lname,prim_street,prim_street2,prim_city,prim_state,prim_postal,prim_country,prim_email,prim_phone1,prim_phone2,prim_phone3,prim_fax1,prim_fax2,prim_fax3,disc_accept) VALUES ('2', '3', '2011', 'asdfasdf', 'asdf', 'asdf', 'asdf', 'asdf', 'asdg', 'asdg', 'United States', 'Yes', 'asdg', 'asdg', 'asdg', 'asdg', 'Mandatory', 'asdg', 'Yes', 'asdg', 'asdg', 'asdg', 'sadg', 'asdg', 'asdg', 'asdg', '12121', 'American Samoa', 'asdf@asdf.com', '121', '111', '1111', '343', '333', '3333', 'Yes');
When all this is run, I get "Unknown column 'emp_city' in 'field list' "
The form field names EXACTLY match what's in the database. The field is in there. I wrote the form first, then a chunk of code to create the table using the exact field names entered into the form to prevent typos. And double checking for the 1597th time, yes, "emp_city" IS in there and all the other field names are correct and the number of fields match the database table as well...
Banging my head against the wall on this. Any ideas? Or do I need to drink some more coffee and take a walk?