Unknown column 'emp_city' in 'field list' - ARGH

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
DedMousie
Forum Newbie
Posts: 12
Joined: Sat Feb 12, 2011 7:21 pm

Unknown column 'emp_city' in 'field list' - ARGH

Post by DedMousie »

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?
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

Re: Unknown column 'emp_city' in 'field list' - ARGH

Post by fugix »

looks to me like you have way too many values going into not enough columns...judging from your insert statement..you also didnt put a ) on the end of your first insert group...thats what i see so far
DedMousie
Forum Newbie
Posts: 12
Joined: Sat Feb 12, 2011 7:21 pm

Re: Unknown column 'emp_city' in 'field list' - ARGH

Post by DedMousie »

fugix wrote:looks to me like you have way too many values going into not enough columns...judging from your insert statement..you also didnt put a ) on the end of your first insert group...thats what i see so far
It got cut off in the paste. The number of columns and values do match. I've counted them and compared column names to the database 100 times now to be sure...

Just tried the paste again - still get's cut off. They *do* match. Promise!
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

Re: Unknown column 'emp_city' in 'field list' - ARGH

Post by fugix »

Can you just post the emp_city field and the value that corresponds to it?
DedMousie
Forum Newbie
Posts: 12
Joined: Sat Feb 12, 2011 7:21 pm

FIXED: Unknown column 'emp_city' in 'field list' - ARGH

Post by DedMousie »

Really Weird - I deleted the field in question from the database (only one test record so far, so no big whoop) and added it back. EXACT same name, type, length, everything. Nothing different.

Now it works with no errors...

MySQL glitch/bug?
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

Re: Unknown column 'emp_city' in 'field list' - ARGH

Post by fugix »

Could be. That error normally means that the field in your table doesn't exist. If you had that in your table then it must have been some sort if glitch. Glad you worked it out though
Post Reply