Forums

DB Read user_id

hcohl 18 Feb, 2017
I created a form with DBRead:
<?php
$user = JFactory::getUser();
return array("user_id" => $user->get("id"));
?>

Now the problem is, if a not registered user opens the form, he gets information of another (not registered) user filled the form before.
How can I give the not registered users an emty form?
Thanks for help.
GreyHead 18 Feb, 2017
Hi hcohl,

Please try this
<?php
$user = \JFactory::getUser();
if ( $user->id > 0 ) {
  return array( 'user_id' => $user->id );
} else {
  return array( ": 'AAA' = 'ZZZ' " );
}
?>
That should return an empty array for a guest.

Bob
hcohl 19 Feb, 2017
Hallo Bob,
thank you for your answer.
But this returns error 1054 - Unknown column 'Data.AAA'.
What do I have to set for "AAA" and "ZZZ"?
HC Ohl
GreyHead 19 Feb, 2017
Answer
Hi hcohl,

Sorry, Not thinking clearly - I've updated this line
return array( ": 'AAA' = 'ZZZ' " );
you just need something there that returns no records.

Bob
hcohl 19 Feb, 2017
Thank you Bob - it works.

HC
This topic is locked and no more replies can be posted.