Hi
hopefully somebody can help me.
I am filtering image link from the body text and then save the image as a filefield. Use the following code:

 $results = db_query("SELECT * FROM {files} WHERE filepath = '%s'", $image_path);
  while($image = db_fetch_array($results)) {
    $node->field_teaser_image[0]['fid'] = $image['fid'];
    $node->field_teaser_image[0]['filename'] = $image['filename'];
    $node->field_teaser_image[0]['filepath'] = $image['filepath'];
    $node->field_teaser_image[0]['status'] = $image['status'];
    $node->field_teaser_image[0]['uid'] = $image['uid'];
    $node->field_teaser_image[0]['filemime'] = $image['filemime'];
    $node->field_teaser_image[0]['filesize'] = $image['filesize'];
    $node->field_teaser_image[0]['timestamp'] = $image['timestamp'];
    $node->field_teaser_image[0]['data']['alt'] = '';
    $node->field_teaser_image[0]['list'] = 1;
  }

It works fine. the image information is saved in the imagefield and I can use the field in Views etc.

But I get this error everytime I save the node:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') FROM content_type_content_listing WHERE = 143' at line 1 query: SELECT count() FROM content_type_content_listing WHERE = 143

The query is not filled in properly. Also the wrong table name is used (should be content_type_blog).
The code around this is on line 950 of filefield.module:

 foreach ($fields as $field) {
    $db_info = content_database_info($field);
    $references += db_result(db_query(
      'SELECT count('. $db_info['columns']['fid']['column'] .')
        FROM {'. $db_info['table'] .'}
        WHERE '. $db_info['columns']['fid']['column'] .' = %d', $file->fid
    ));

If anybody can tell me what else I should do or shed some light on why the query is incompletely filled in, would be much appreciated.

Comments

Max_Headroom’s picture

Status: Active » Fixed

Found handbook page:
Programmatically creating FileField entries
http://drupal.org/node/330421

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.