- Posts: 14
- Thank you received: 0
Using PHP code to retrieve current user name?
- John Waraksa
-
Topic Author
- Offline
- New Member
-
//<code>
$db =& JFactory::getDBO();
$db->setQuery("SELECT last_name FROM syx8v_osmembership_subscribers");
$result = $db->loadResult();
return $result;
//</code>
This only retrieves the very first user name in database, not the current user logged into site. Any suggests how to get last name of user logged into site automatically into renewal form?
Please Log in or Create an account to join the conversation.
- Tuan Pham Ngoc
- Offline
- Administrator
-
Your code is not correct. Please try this one:
That should work OK
Tuan
Please Log in or Create an account to join the conversation.
- John Waraksa
-
Topic Author
- Offline
- New Member
-
- Posts: 14
- Thank you received: 0
I attempted to modify this code without success. I would appreciate any other suggestions.
Thank you,
John
Please Log in or Create an account to join the conversation.
- Tuan Pham Ngoc
- Offline
- Administrator
-
Actually, I don't understand what form you are talking about. The code itself is correct, not sure how you put that data to the form.
Could you please explain more details so that I can guide you? Maybe you can submit a support ticket so that we can check the code for you?
Regards,
Tuan
Please Log in or Create an account to join the conversation.
- John Waraksa
-
Topic Author
- Offline
- New Member
-
- Posts: 14
- Thank you received: 0
I am using another plugin for forms called RSForm! Pro (from RSJoomla!). When building forms, this software allows putting in PHP code for default text Input Fields. I just assumed it would be easy to grab information from backend database about person logged into OSSolution Membership Pro.
Maybe another approach would be to grab info from Joomla itself. Perhaps I can also get help from RSJoomla! forum. I really do appreciate your quick responses.
Thank you!
Please Log in or Create an account to join the conversation.
- Calum
- Offline
- Elite Member
-
- Posts: 257
- Thank you received: 34
But not sure why the example give before doesn't work - its not a wrapping issue as the SQL select splits over two lines on my screen?
Please Log in or Create an account to join the conversation.
- John Waraksa
-
Topic Author
- Offline
- New Member
-
- Posts: 14
- Thank you received: 0
return $result;
So complete functioning code for RSForm! Pro is:
//<code>
$user = JFactory::getUser();
$db = JFactory::getDBO();
$db->setQuery("SELECT last_name FROM syx8v_osmembership_subscribers WHERE user_id=".$user->id);
$result = $db->loadResult();
return $result;
//</code>
Again, thank you for your help as I probably would have never figured out a working PHP code.
Please Log in or Create an account to join the conversation.
- Alan Bennett
- Offline
- Elite Member
-
- Posts: 188
- Thank you received: 28
Please Log in or Create an account to join the conversation.
- Tuan Pham Ngoc
- Offline
- Administrator
-
John Waraksa wrote: Yes, your original PHP code was correct but missing one required line:
return $result;
So complete functioning code for RSForm! Pro is:
//<code>
$user = JFactory::getUser();
$db = JFactory::getDBO();
$db->setQuery("SELECT last_name FROM syx8v_osmembership_subscribers WHERE user_id=".$user->id);
$result = $db->loadResult();
return $result;
//</code>
Again, thank you for your help as I probably would have never figured out a working PHP code.
As I don't know how rsform works, I could only give you the basic code you need. Glad to hear that you figure it out
Tuan
Please Log in or Create an account to join the conversation.
Support
Documentation
Information
The Joomla! name and logo is used under a limited license granted by Open Source Matters the trademark holder in the United States and other countries.