This topic is locked
[SOLVED]

 Inserting into another table

2/17/2018 4:38:11 AM
PHPRunner General questions
P
PaulM author

I would like to add the id of the record I'm adding to a field in another table but am not getting any joy is this the correct way to do it? I've tried 2 ways to do it without any luck
global $dal;

$tblEvents = $dal->Table("Property_Landlord_Tenant_Link");

$tblEvents->Value["PLT_P_id"]=$values['P_id'];

$tblEvents->Add();
$sql = "INSERT INTO Property_Landlord_Tenant_Link (PLT_P_id) values ($values[P_id])";

CustomQuery($sql);
Any ideas?
I can add it when done through phpadmin using a hard-coded value

jadachDevClub member 2/17/2018



I would like to add the id of the record I'm adding to a field in another table but am not getting any joy is this the correct way to do it? I've tried 2 ways to do it without any luck
global $dal;

$tblEvents = $dal->Table("Property_Landlord_Tenant_Link");

$tblEvents->Value["PLT_P_id"]=$values['P_id'];

$tblEvents->Add();
$sql = "INSERT INTO Property_Landlord_Tenant_Link (PLT_P_id) values ($values[P_id])";

CustomQuery($sql);
Any ideas?
I can add it when done through phpadmin using a hard-coded value


Make sure you are doing after record added event. Also you should use $keys['P_id'] for PK.

P
PaulM author 2/17/2018

Thanks Jadach,
I've tried both
$sql = "INSERT INTO Property_Landlord_Tenant_Link (PLT_P_id) values ($keys[P_id])";

CustomQuery($sql);
global $dal;

$tblEvents = $dal->Table("Property_Landlord_Tenant_Link");

$tblEvents->Value["PLT_P_id"]= $keys['P_id'];

$tblEvents->Add();
But still neither of them work. the add screen just stays the same without adding the record to the original or the other tables. Is there a way I can debug it?
I've just done this and it worked
$sql = "INSERT INTO Property_Landlord_Tenant_Link (PLT_P_id) values (9)";

CustomQuery($sql);
so now I just need to get the $keys[P_id] working
Any ideas?



Make sure you are doing after record added event. Also you should use $keys['P_id'] for PK.