This topic is locked

Inserting data into a table from another table on Add or Edit Event

9/16/2007 10:15:56 PM
PHPRunner General questions
D
dilbertbert author

I need to insert data into a table from another table in the Add and Edit events.
This example involves paying owners of a crude oil well.
I have a table that contains owners data including a social security number. When I add or edit a record in a division of interst (doi) table I want the social security number from the owners table to insert into the doi file. Here is an example of the tables:
_owners

ownerid

name

addr1

addr2

city

st

zip

ssnumber
_doi

wellid

ownerid

ssnumber

doiamount
As you can see the ownerid is in both tables and when they match I want the ssnumber in the _owners table to populate the ssnumber in the _doi table.
I am very new at this and am PHP illiterate, if someone could give me an example of what the code should look like in the Add and Edit events I would be forever gratefull!!
Thank You!

Alexey admin 9/17/2007

Hi,
sure, here is the code for Before record added/updatedevent:

global $conn;

$sql = "select * from _owners where ownerid = ".$values["ownerid"];

$rs = db_query($sql,$conn);

if($data = db_fetch_array($rs))

$values["ssnumber"]=$data["ssnumber"];