Rule with if statement prevents users from saving their user account I have set up a rule that is causing some odd behaviour.

The event of the rule is: "After updating an existing account"

However the rule is preventing the user to save the data of his particular useraccount.

Allthough drupal says "The changes have been saved." non of the filled in data of the useraccount is saved.eg password etc

It looks like the second condition (If: NOT Data value is empty) is causing the bug.
However i dont know what the alternative should be.

Thanks

Here my rule:

{
  "rules_if_oginvite_redirect_to_oghome_after_userpagesave_and_remo" : {
    "LABEL" : "If registered by mail redirect to oghome or mypage",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "TAGS" : [ "Redirect" ],
    "REQUIRES" : [ "rules", "rules_conditional", "php" ],
    "ON" : { "user_update" : [] },
    "IF" : [
      { "user_has_role" : {
          "account" : [ "site:current-user" ],
          "roles" : { "value" : { "2" : "2", "4" : "4" } },
          "operation" : "OR"
        }
      },
      { "NOT user_has_role" : {
          "account" : [ "site:current-user" ],
          "roles" : { "value" : { "3" : "3" } }
        }
      }
    ],
    "DO" : [
      { "user_remove_role" : {
          "account" : [ "site:current-user" ],
          "roles" : { "value" : { "4" : "4" } }
        }
      },
      { "CONDITIONAL" : [
          {
            "IF" : { "NOT data_is_empty" : { "data" : [ "site:current-user:og-membership--1" ] } },
            "DO" : [
              { "php_eval" : { "code" : "global $user;\r\n$uid = $user-\u003Euid;\r\n$result = db_query ( \u0022SELECT * FROM {og_membership}\r\nWHERE etid = :uid\r\nand entity_type = \u0027user\u0027\r\norder by gid DESC\u0022, array (\u0027:uid\u0027 =\u003E $uid ) );\r\n\r\n\/\/ get the results\r\nforeach ( $result as $row ) {\r\n\/\/ Do stuff with $record, which is an object\r\n$gid = $row-\u003Egid;\r\nbreak; \/\/get the latest one by breaking here\r\n}\r\n$_SESSION[\u0027ses_user_group_gid\u0027] = $gid;" } },
              { "redirect" : { "url" : "\u003C?php print \u0022node\/\u0022.$_SESSION[\u0027ses_user_group_gid\u0027];  ?\u003E" } }
            ]
          },
          { "ELSE" : [ { "redirect" : { "url" : "mypage" } } ] }
        ]
      }
    ]
  }
}
As an observation I would advise against using PHP directly in a rule if it can be avoided. Much better to put your logic into a custom action and call it.

But looking at the code you supply, you should note that the user account referred to in the rule and the global current one need not be the same (an administrator may edit someone's profile, for example). You should be using the account passed in to the rule throughout, not site:current-user. Also the user update condition, IIRC, may be called when a user object is saved in other circumstances than a profile edit, so the redirect won't be appropriate. 

So in order to be sure the user is editing their own profile, you should add a condition to the rule which compares the account's uid to that of the current user to make sure they are the same.