Index: vtigerolservice.php
===================================================================
--- vtigerolservice.php	(revision 13354)
+++ vtigerolservice.php	(working copy)
@@ -529,20 +529,20 @@
 		}
 
 		$namelist = explode(" ", $contact["lastname"]);
-		$middlename = "";
+        $middlename_arr = array();
 		if(isset($namelist))
 		{
 			if(count($namelist) >= 2) 
 			{
 				$contact["lastname"] = $namelist[count($namelist)-1];       	
-				for($i=0; $i<count($namelist)-2; $i++)
+				for($i=0; $i<count($namelist)-1; $i++)
 				{
 				  if($namelist[$i] != '')
-					 $middlename[] = $namelist[$i];
+					 $middlename_arr[] = $namelist[$i];
 				}
-				if(isset($middlename))
+				if(count($middlename_arr)>0)
 				{
-					$middlename = implode(" ",$middlename);
+					$contact["middlename"] = implode(" ",$middlename_arr);
 				}
 			}
 		}