Shouldn't this line
PHP Code:
$query='SELECT * FROM `memfiles` WHERE `field` = \'$field\' ';
look like this instead
PHP Code:
$query=sprintf("SELECT * FROM `memfiles` WHERE `field` = '%s'", $field);
The main thing is $field won't get interpolated into a single quoted string, use sprintf or double quotes.