Arrays and "Unknown column in 'where clause'"

Small issue here. I think I know what the problem is but I don’t know how to fix it.

	
		$bits = $wheres = array();
		foreach ( (array) array_keys($data) as $field ) {
			if ( isset($data[$field]) )
				$form = $data[$field];
			$bits[] = "`$field` = {$form}";
		}

		foreach ( (array) array_keys($where) as $field ) {
			if ( isset($where[$field]) )
				$form = $where[$field];
			$wheres[] = "`$field` = {$form}";
		}
		var_dump($wheres);
		   echo "UPDATE `$table` SET " . implode( ', ', $bits ) . ' WHERE ' . implode( ' AND ', $wheres)."<br/>";

	mysql_query("UPDATE `$table` SET " . implode( ', ', $bits ) . ' WHERE ' . implode( ' AND ', $wheres )) or die(mysql_error());

The two for each segments are meant to loop through submitted arrays of paramaters for an sql query and they work fine.

The echoed SQL statement is just me seeing the output of everything and it appears perfect, as such.

 UPDATE `posts` SET `post_parent` = 300 WHERE `post_parent` = 270 AND `post_type` = page

But the actual query returns the error “Unknown column ‘page’ in ‘where clause’”

I THINK it’s because “page” lacks quotes but I don’t know how to adjust the array to fix the issue. “page” is part of $where as a string pulled from a database.

So is there a way I can get quotes around the entry ONLY if it is a string as the $where variable has multiple parameters; in this case an int (The post ID) and a string (page). Or am I completely wrong and this is not the issue?

That is indeed the issue.

if(is_numeric($value)) { //append as is }
else { //append with quotes around it }

Yesssss, thank you StarLion. I had a different loop for an INSERT but couldn’t get it to work for this. It is working now and performed my test update.

Thank you again.