--- imagefield_migrate.php  2008-06-21 14:28:08.000000000 -0500
+++ imagefield_migrate.php  2008-06-21 14:28:26.000000000 -0500
@@ -8,10 +8,10 @@
 * --------------
 * - You must create a single imagefield field to which all your images will be migrated. You
 * should create a new content type for that.
+* - The imagefield's Image path should be identical to the image.module's configured path (i.e. 'images' by default)
+* - The imagefield should be configured for 'multiple values'.
 * - If you use image_attach, you should also add this imagefield field to each content type that
 * is image_attach enabled.
<?php
-* - The imagefield should be configured for 'multiple values'.
-* - The imagefield's Image path should be identical to the image.module's configured path (i.e. 'images' by default)
 *
 * USAGE
 * ----------
@@ -51,7 +51,7 @@ $fid = $field_name. '_fid';
 $title = $field_name. '_title';
 $alt = $field_name. '_alt';
 
-$sql = "INSERT INTO $table (vid,delta,nid,$fid, $title, $alt) SELECT n.vid, 0 as delta, n.nid,f.fid,n.title,n.title FROM node n, files f WHERE n.nid = f.nid AND n.type = 'image' AND f.filename = '_original'";
+$sql = "INSERT INTO {$table} (vid, delta, nid, $fid, $title, $alt) SELECT n.vid, 0 AS delta, n.nid, f.fid, n.title, n.title FROM {node} n INNER JOIN {files} f ON n.nid = f.nid WHERE n.type = 'image' AND f.filename = '_original'";
 if (db_query($sql)) {
   echo "- $table populated.<br />\n";
 }
@@ -59,13 +59,13 @@ if (db_query($sql)) {
 // Set the needed filename in the files table.
 $image_path = file_create_path(variable_get('image_default_path', 'images'));
 $length = strlen($image_path)+2;
-$sql = "UPDATE files SET filename = SUBSTRING(filepath, $length) WHERE filename = '_original'";
+$sql = "UPDATE {files} SET filename = SUBSTRING(filepath, $length) WHERE filename = '_original'";
 if (db_query($sql)) {
   echo "- files table updated<br />\n";
 }
 
 // Change the content type from 'image' to the configured type.
-$sql = "UPDATE node SET type = '%s' WHERE type = 'image'";
+$sql = "UPDATE {node} SET type = '%s' WHERE type = 'image'";
 db_query($sql, $type_name);
 
 // Loop over the image_attach records
@@ -97,7 +97,7 @@ if (module_exists('video_image')) {
     while ($row = db_fetch_object($result)) {
       $node = node_load($row->nid);
       if ($iid = $node->iid) {
-        $sql = "UPDATE $table SET nid = $row->nid, vid = $row->vid WHERE nid = $iid";
+        $sql = "UPDATE {$table} SET nid = $row->nid, vid = $row->vid WHERE nid = $iid";
         if (db_query($sql)) {
           // Successful update. Now unpublish the standalone node that we just made.
           $sql = "UPDATE {node} SET status = 0 WHERE nid = $iid";
@@ -113,6 +113,6 @@ if (module_exists('video_image')) {
 }
 
 // Clear CCK cache.
-$sql = "DELETE FROM cache_content";
+$sql = "DELETE FROM {cache_content}";
 db_query($sql);
