Hello!
I need a Triggered rule that should be evaluated on event "User account has been created" and this rule should check if user whith particular uid exists and if it's true then add some userpoints to the account of the user who is just registered. What PHP code I should put into a condition "Rules - Check a truth value" to check if particular uid exists? This uid (for example uid=103) was entered by registered user (who is just registered and for example he have got a uid=134) into the CCK field at his own Content Profile node and is accessible directly in PHP evaluation field by token replacement pattern [account:content-profile-profile-referral].
So the logic is:
1) user 134 registered and he has typed into the registration form that he was invited by user with uid=103;
2) if user with uid=103 really exists then the user with uid=134 gets some userpoints;
3) if user with uid=103 does not exist - just registered user with uid=134 gets nothing.
By s866 on
Comments
Given you have the
Given you have the uid
PHP code could perform a query
Thank you nevets for your answer! But I think it is not what I'm looking for. I simply need that PHP code could perform a query and then return "False" if it determines that user with uid=103 does not exist or "True" if user with uid=103 does exist.
Maybe this code might look like this?
at the moment of executing PHP code the token [account:content-profile-profile-referral] substituted with a number that is an exact uid (in this case number 103). how to return "false" or "true" properly?
PHP code could perform a query
maybe like this?
Rules condition PHP: how to check if uid exists?
Finaly I made it to work. I used another event - "Content is going to be saved", and added 3 conditions to this rule:
1) Saved content is profile (Content profile);
2) Saved content is new;
3) and Custom PHP code:
thanks to all who attended and answered :)
Extra "(" in Code
Thanks for your post, s866 it helped me out!
Just as a note to others, the code should read:
db_result(db_query("SELECT COUNT(*) FROM {users} WHERE uid = '%d'", '[node:field_referral-formatted]'));
if ($answer >= 1){
return TRUE;
}
else{
return FALSE;
}
You left extra parentheses in the db_result() function from the previous iteration when you were using it inside an if statement.
Notice that I omitted the PHP brackets, as rules won't work if you include them...