This topic is locked

Insert Form data into another table

9/7/2009 6:35:27 AM
PHPRunner General questions
F
fpilot author

Hello everybody,
I searched for this in the forum but didn't find anything, pls refer me to the link if it has already been answered.
I want to add JobId into commissions table after a new job has been added. But as The JobId will only be created after the record has been added therefore I cannot add JobId which is required later for my update querry. I have tried after record added but somehow is not working, here is the code:

/*****

global $conn;

$CId=$values["CId"];

$QuotedPrice=$values["QuotedPrice"];

$Date=$values["Date"];

$JId=$values["JId"];

$sqlSelect = "select ParentId from customers where CId=$CId";

$rsCustomer = db_query($sqlSelect,$conn);

$data=db_fetch_array($rsCustomer);

$Parent=$data["ParentId"];

$sqlSelectGParent = "select ParentId from customers where CId=$Parent";

$rsGParent = db_query($sqlSelectGParent,$conn);

$dataGParent=db_fetch_array($rsGParent);

$GParent=$dataGParent["ParentId"];
$strSQLInsert = "insert into Commissions(JId, Customer,Parent,GrandParent,Price,Date)values($JId,$CId,$Parent,$GParent,$QuotedPrice,$Date)";

db_exec($strSQLInsert,$conn);
}

return true;

*
/

Sergey Kornilov admin 9/7/2009

I recommend to print SQL query on the web page to make sure it looks right.

http://www.xlinesoft.com/phprunner/docs/debugging_tips.htm
Probably you miss single quotes around text fields. I recommend to use DAL that takes care of this.

More info: http://www.xlinesoft.com/phprunner/docs/data_access_layer.htm