Index: bp-xprofile/bp-xprofile-template.php
===================================================================
--- bp-xprofile/bp-xprofile-template.php
+++ bp-xprofile/bp-xprofile-template.php
@@ -325,7 +325,10 @@ function bp_the_profile_field_edit_value() {
 		 * Check to see if the posted value is different, if it is re-display this
 		 * value as long as it's not empty and a required field.
 		 */
-		if ( isset( $_POST['field_' . $field->id] ) && isset( $field->data->value ) && $field->data->value != $_POST['field_' . $field->id] ) {
+		if ( !isset( $field->data->value ) )
+			$field->data->value = '';
+		
+		if ( isset( $_POST['field_' . $field->id] ) && ( $field->data->value != $_POST['field_' . $field->id] ) ) {
 			if ( !empty( $_POST['field_' . $field->id] ) )
 				$field->data->value = $_POST['field_' . $field->id];
 		}
@@ -417,14 +420,15 @@ function bp_the_profile_field_options( $args = '' ) {
 
 		switch ( $field->type ) {
 
-			case 'selectbox': case 'multiselectbox':
-				if ( 'multiselectbox' != $field->type )
-					$html .= '<option value="">--------</option>';
+			case 'selectbox':
+				$html .= '<option value="">--------</option>';
+
+				if ( !$original_option_values = maybe_unserialize( BP_XProfile_ProfileData::get_value_byid( $field->id ) ) )
+					$original_option_values = $_POST['field_' . $field->id];
 
-				$original_option_values = maybe_unserialize( BP_XProfile_ProfileData::get_value_byid( $field->id ) );
 				$option_values = (array) $original_option_values;
 
-				for ( $k = 0; $k < count( $options ); $k++ ) {
+				for ( $k = 0, $count = count( $options ); $k < $count; ++$k ) {
 					// Check for updated posted values, but errors preventing them from being saved first time
 					foreach( $option_values as $i => $option_value ) {
 						if ( isset( $_POST['field_' . $field->id] ) && $_POST['field_' . $field->id] != $option_value ) {
@@ -432,32 +436,63 @@ function bp_the_profile_field_options( $args = '' ) {
 								$option_values[$i] = $_POST['field_' . $field->id];
 						}
 					}
-
 					$selected = '';
 
 					// Run the allowed option name through the before_save
 					// filter, so we'll be sure to get a match
 					$allowed_options = xprofile_sanitize_data_value_before_save( $options[$k]->name, false, false );
 
-					// First, check to see whether the user-entered value
-					// matches
+					// First, check to see whether the user-entered value matches
 					if ( in_array( $allowed_options, (array) $option_values ) )
 						$selected = ' selected="selected"';
 
-					// Then, if the user has not provided a value, check for
-					// defaults
-					if ( !is_array( $original_option_values ) && empty( $option_values ) & $options[$k]->is_default_option )
+					// Then, if the user has not provided a value, check for defaults
+					if ( !is_array( $original_option_values ) && empty( $option_values ) && $options[$k]->is_default_option )
 						$selected = ' selected="selected"';
 
 					$html .= apply_filters( 'bp_get_the_profile_field_options_select', '<option' . $selected . ' value="' . esc_attr( stripslashes( $options[$k]->name ) ) . '">' . esc_attr( stripslashes( $options[$k]->name ) ) . '</option>', $options[$k] );
 				}
 				break;
 
+			case 'multiselectbox':
+
+				$original_option_values = '';
+				if ( !$original_option_values = maybe_unserialize( BP_XProfile_ProfileData::get_value_byid( $field->id ) ) )
+					$original_option_values = $_POST['field_' . $field->id];
+
+				$option_values = (array) $original_option_values;
+
+				for ( $k = 0, $count = count( $options ); $k < $count; ++$k ) {
+					// Check for updated posted values, but errors preventing them from being saved first time
+					foreach( $option_values as $i => $option_value ) {
+						if ( isset( $_POST['field_' . $field->id] ) && $_POST['field_' . $field->id][$i] != $option_value ) {
+							if ( !empty( $_POST['field_' . $field->id][$i] ) )
+								$option_values[] = $_POST['field_' . $field->id][$i];
+						}
+					}
+					$selected = '';
+
+					// Run the allowed option name through the before_save
+					// filter, so we'll be sure to get a match
+					$allowed_options = xprofile_sanitize_data_value_before_save( $options[$k]->name, false, false );
+
+					// First, check to see whether the user-entered value matches
+					if ( in_array( $allowed_options, (array) $option_values ) )
+						$selected = ' selected="selected"';
+
+					// Then, if the user has not provided a value, check for defaults
+					if ( !is_array( $original_option_values ) && empty( $option_values ) && $options[$k]->is_default_option )
+						$selected = ' selected="selected"';
+
+					$html .= apply_filters( 'bp_get_the_profile_field_options_multiselect', '<option' . $selected . ' value="' . esc_attr( stripslashes( $options[$k]->name ) ) . '">' . esc_attr( stripslashes( $options[$k]->name ) ) . '</option>', $options[$k] );
+				}
+				break;
+
 			case 'radio':
 				$html .= '<div id="field_' . $field->id . '">';
 				$option_value = BP_XProfile_ProfileData::get_value_byid( $field->id );
 
-				for ( $k = 0; $k < count( $options ); $k++ ) {
+				for ( $k = 0, $count = count( $options ); $k < $count; ++$k ) {
 					// Check for updated posted values, but errors preventing them from being saved first time
 					if ( isset( $_POST['field_' . $field->id] ) && $option_value != $_POST['field_' . $field->id] ) {
 						if ( !empty( $_POST['field_' . $field->id] ) )
@@ -488,16 +523,15 @@ function bp_the_profile_field_options( $args = '' ) {
 						$option_values = $_POST['field_' . $field->id];
 				}
 
-				for ( $k = 0; $k < count( $options ); $k++ ) {
+				for ( $k = 0, $count = count( $options ); $k < $count; ++$k ) {
 					$selected = '';
 
 					// First, check to see whether the user's saved values
 					// match the option
-					for ( $j = 0; $j < count( $option_values ); $j++ ) {
+					for ( $j = 0, $count = count( $option_values ); $j < $count; ++$j ) {
 
 						// Run the allowed option name through the
-						// before_save filter, so we'll be sure to get a
-						// match
+						// before_save filter, so we'll be sure to get a match
 						$allowed_options = xprofile_sanitize_data_value_before_save( $options[$k]->name, false, false );
 
 						if ( $option_values[$j] == $allowed_options || @in_array( $allowed_options, $value ) ) {
