This topic is locked

Insert a SQL Query, with a variable on the statement

4/23/2008 9:15:46 PM
PHPRunner General questions
B
bozzo author

People, I'm a begginer on PHPr and want to do some stuff regarding database operations...
Like, I want to do a query on a event of a page....

I want this

update foreign_table set COLUMN='VALUE' where foreign_table_Field=present_table_field


Putting into words, I want to update a record on another table using the events page (when I edit and add a record), selecting the record using a key on the "present" table....

I'm not sure if it's clear what I want to do...But any help will be extremely welcomed....
Thank you all....

J
Jane 4/24/2008

Yuri,
I recommend you to use After record added/After record updated events for this purpose.

All entered values are stored in the $values array, key values are stores in the $keys array.

Here is a sample:

global $conn;

$strUpdate = "update foreign_table set COLUMN='".$values["FieldName"]."' where foreign_table_Field=".$values["present_table_field"];

db_exec($strUpdate,$conn);

B
bozzo author 4/24/2008

Yuri,

I recommend you to use After record added/After record updated events for this purpose.

All entered values are stored in the $values array, key values are stores in the $keys array.

Here is a sample:


Thanks Jane...as usual, worked like a charm....