This topic is locked

Add New Record Joined Tables

1/8/2016 10:17:10 PM
PHPRunner General questions
S
stiven author

Hello Everyone,
Hopefully someone has across with this and knows a solution. I have an add table joined to a few other tables. my plan is to only insert records in the other tables if there is any data on those specific fields for that table if there isn't then there is no need to insert a record in another table. the problem here is that in order for the record to be added I need to unset all variables that are from joined tables because if not it will throw an error. so what I tried to do is add the record into the joined table if there is any data in that field for that table the problem is because the record has not been added to the database I don't have the key column value yet. I can not add this code in the BeforeAdd event because there is no $keys values there I tried in the CustomAdd event but the $keys['key_column'] is returning 0. and the record is not being added here is a sample from my code.



////disposition

if(!empty($values['final_disposition'])){

$strSQLInsert = "INSERT INTO lat_vital_disposition (case_no,final_disposition,disp_address,disp_city,disp_state,disp_zipcode) VALUES ('".$keys['case_no']."','".$values['final_disposition']."','".$values['disp_address']."','".$values['disp_city']."','".$values['disp_state']."','".$values['disp_zipcode']."')";

db_exec($strSQLInsert,$conn);

}

///unset variables for disposition

unset($values['final_disposition']);

unset($values['disp_address']);

unset($values['disp_city']);

unset($values['disp_state']);

unset($values['disp_zipcode']);


Thank you

Sergey Kornilov admin 1/11/2016

$keys['key_column'] will be only accessible in AfterAdd event, after record was actually added to the database. You will need to move your INSERT code to AferAdd event.
You will also have to save those field values you unsetting to session variables so you can still use them in AfterAdd event i.e.

$_SESSION['final_disposition']=$values['final_disposition']

unset($values['final_disposition']);