Hi Guys, please help. I have a form where only registered users can access. Now in the first part of the form I have a php action pulling data from the DB until I get to the following:
It will return nothing because it cant find the current userid of the logged in user, however if I change the $userid to the id of a logged in member the results display correctly. How do I dynamically use the above code to retrieve user id and input it after the WHERE call?
Thanks
Please bare in mind Im new to php code.
<?php
$db = JFactory::getDBO();
$db->setQuery('SELECT cf_deladdress FROM #__uu_users WHERE user_id=$userid');
$databaseTitle = $db->loadResult();
?>
<?php echo $databaseTitle; ?>
It will return nothing because it cant find the current userid of the logged in user, however if I change the $userid to the id of a logged in member the results display correctly. How do I dynamically use the above code to retrieve user id and input it after the WHERE call?
Thanks
Please bare in mind Im new to php code.
Hi mrocco,
Please try:
Bob
Please try:
<?php
$user =& JFactory::getUser();
$db =& JFactory::getDBO();
$query = "
SELECT `cf_deladdress`
FROM `#__uu_users`
WHERE `user_id` = {$user->id} ;
";
$db->setQuery($query);
$databaseTitle = $db->loadResult();
echo $databaseTitle;
?>
Bob
Hi Bob, thanks I tried that, still no return.
Anything else I can try.
I have got the GH load user info addon aswell, could that be causing it not to display?
Joomla 2.5.11
Chronoforms v4
PS if I use your code and replace {$user-id} with the actual user ID number eg 949 it works perfectly.
If I use the following it displays the ID correctly:
Anything else I can try.
I have got the GH load user info addon aswell, could that be causing it not to display?
Joomla 2.5.11
Chronoforms v4
PS if I use your code and replace {$user-id} with the actual user ID number eg 949 it works perfectly.
If I use the following it displays the ID correctly:
<?php
$user =& JFactory::getUser();
if (!$user->guest) {
echo 'You are logged in as:<br />';
echo 'User name: ' . $user->username . '<br />';
echo 'Real name: ' . $user->name . '<br />';
echo 'User ID : ' . $user->id . '<br />';
}
?>
Hi mrocco,
The query looks OK to me - try debugging it with a few 'echo' statements to see exactly what is happening in your code.
The User Info [GH] action shouldn't cause a problem; try removing it to check though.
Bob
The query looks OK to me - try debugging it with a few 'echo' statements to see exactly what is happening in your code.
The User Info [GH] action shouldn't cause a problem; try removing it to check though.
Bob
This topic is locked and no more replies can be posted.