--- old\user_badges.admin.inc	2011-10-10 00:26:15.984375000 -0400
+++ new\user_badges.admin.inc	2011-10-10 09:55:34.453125000 -0400
@@ -186,7 +186,7 @@ function user_badges_edit_form($form, $f
   // Are we using a library image or an image URL?
   $libraryimage = '';
   $imageurl = '';
-  if ( isset($edit) && valid_url($edit->image, TRUE) ) {
+  if (isset($edit) && valid_url($edit->image, TRUE)) {
     $imageurl = $edit->image;
     $libraryimage = '';
   }
@@ -364,21 +364,28 @@ function user_badges_edit_form_validate(
 function user_badges_edit_form_submit($form, &$form_state) {
   $edit = $form_state['values'];
   $edit = (object) $edit;
+  if (isset($edit->bid)) {
+    // If the badge already exists, delete it and re-insert it.
+    $result = db_merge('user_badges_badges')
+      ->key(array('bid' => $edit->bid));
+  }
+  else {
+    // If the badge does not exist, insert it.
+    $result = db_insert('user_badges_badges');
+  }
 
   $image = $edit->imageurl ? trim($edit->imageurl) : 'public://' . $edit->image;
 
-  // If the badge already exists, delete it and re-insert it.
-  $result = db_merge('user_badges_badges')
-    ->key(array('bid' => $edit->bid))
-    ->fields(array(
-      'name' => array(trim($edit->name),
+  // Add the rest of the fields.
+  $result->fields(array(
+      'name' => trim($edit->name),
       'image' => $image,
       'weight' => $edit->weight,
       'href' => (!empty($edit->href) ? trim($edit->href) : NULL),
       'unhideable' => $edit->unhideable,
       'fixedweight' => $edit->fixedweight,
       'doesnotcounttolimit' => $edit->doesnotcounttolimit,
-      'tid' => (!empty($edit->tid) ? $edit->tid : NULL))
+      'tid' => (!empty($edit->tid) ? $edit->tid : NULL),
     ))
     ->execute();
 
@@ -388,7 +395,6 @@ function user_badges_edit_form_submit($f
   else {
     drupal_set_message(t('There was a problem saving the badge information into the database.'));
   }
-  $form_state['redirect'] = 'admin/user/user_badges';
 }
 
 /**
