This topic is locked

Updating One Table When Updating Another

1/18/2009 5:39:24 PM
PHPRunner General questions
G
guy author

Hi all,
I hope you can help me with a problem I'm having.
Basically I have a table in my database (let's call it table A) which I'd like to to use to record updates my users make to another table (lets call it table <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=10672&image=1&table=forumtopics' class='bbc_emoticon' alt='B)' />.
If a user updates or adds to table B I wanted table A to show the users user name (username) and the changes made (changes).
I think I need to use the Events feature in the program but I'm very unsure of the script that I need to write to do this.
Firstly, does that make sense, and secondly, can anybody help?
Many thanks in advance,
Liu

A
alang 1/18/2009

Yes that makes sense - there are two events. One for the Add (After record added) and one for the edit (After record updated). Typically your code for the table B events might be something like:
global $conn;

$query = "INSERT INTO TableA ... VALUES ($_SESSION["UserID"] ...<change data from event parameters fields here>...";

db_exec($query, $conn);

J
Jane 1/20/2009

Hi,
use Before record added and Before record updated events on the Events tab for Table B.

Here is a sample:

global $conn,$strTableName;

$str = "INSERT INTO TableA (UserNameField,TableNameField,UpdateField) VALUES ('".$_SESSION["UserID"]."','".$strTableName."','field name')";

db_exec($query, $conn);



where UserNameField, TableNameField, UpdateField are your actual field names.