This topic is locked

OwnerID on a users table

10/25/2011 4:19:04 AM
PHPRunner General questions
S
Sami author

Hello
I have a list of members of a group in a table (T1) and they can see and edit their own data only in another table (T2)
my problem is when the admin add new records in (T2) with the OwnerID of (T1), the record field changes automatically to the admin's OwnerID
I hope you understand what I mean and please tell me how to prevent this change automatically...

C
cgphp 10/25/2011

In the Before record updated event of table T2 set the OwnerID field value to the old value:

$values['OwnerID'] = $oldvalues['OwnerID'];

return true;
S
Sami author 10/25/2011



In the Before record updated event of table T2 set the OwnerID field value to the old value:

$values['OwnerID'] = $oldvalues['OwnerID'];

return true;



There is no Before record updated on the add page it's only on the edit page but I've tried it in both Before record updated on the edit page and on Before record added on the add page but it shows me an error

Undefined variable: oldvalues
C
cgphp 10/25/2011

Sorry, I had misunderstood your request. $oldvalues is only available for the Edit page. Try to update the record after it has been added in the "After record added" event:

global $conn;

db_exec("UPDATE T2_table_name SET owner_field_name = ? WHERE primary_id_field_name = ".$keys['primary_id_field_name'],$conn);


where ? is the id of the owner

S
Sami author 10/25/2011

It shows a php error n°256

Unknown column 'admin' in 'where clause'


I'm trying to solve the prob...

Sergey Kornilov admin 10/26/2011

If primary key is a text field you need to add single quotes around key value:

global $conn;

db_exec("UPDATE T2_table_name SET owner_field_name = ? WHERE primary_id_field_name = '".$keys['primary_id_field_name']."'",$conn);