This topic is locked

Before Record Updated

12/27/2009 2:37:04 PM
PHPRunner General questions
C
capp author

Hi Everyone,
I'm quite new to adding in my own custom code for the db, but my main goal is as follows:
I have three tables: engineers, updates, and users. I'd like to have it so that when a user edits a record in the engineer's table, that update is mirrored to the updates table.

I can then have a list of all the updates that have occurred. I attempted to use the following code, but I'm sure I'm missing quite a bit... Thanks in advance!

$strSQLSave = "INSERT INTO Upates (ENG_FNAME, ENG_LNAME) values (";
$strSQLSave .= $values["FirstName"].",";

$strSQLSave .= $values["LastName"];
$strSQLSave .= ")";

db_exec($strSQLSave,$conn);


The Firstnameand LastNameare to fields from the engineers table. What would be required to have the this data, timestamp, and the username from the User's table show up in the updates table?

J
Jane 12/28/2009

Hi,
please see my changes below:

$strSQLSave = "INSERT INTO Updates (ENG_FNAME, ENG_LNAME, Fieldname1, FieldName2) values ('";
$strSQLSave .= $values["FirstName"]."','";

$strSQLSave .= $values["LastName"]."','";

$strSQLSave .= $_SESSION["UserID"]."',";

$strSQLSave .= "now()";
$strSQLSave .= ")";

db_exec($strSQLSave,$conn);



where Fieldname1, FieldName2 are your actual field names in the updates table.

C
capp author 1/3/2010



Hi,
please see my changes below:

$strSQLSave = "INSERT INTO Updates (ENG_FNAME, ENG_LNAME, Fieldname1, FieldName2) values ('";
$strSQLSave .= $values["FirstName"]."','";

$strSQLSave .= $values["LastName"]."','";

$strSQLSave .= $_SESSION["UserID"]."',";

$strSQLSave .= "now()";
$strSQLSave .= ")";

db_exec($strSQLSave,$conn);



where Fieldname1, FieldName2 are your actual field names in the updates table.


Hi Jane,
I've tried what you suggested but the UserId doesn't show.. I don't need to declare it in some fashion do I?
thanks

J
Jane 1/7/2010

It's difficult to tell you what's happening without seeing actual files.
Please publish your project on Demo Account and open a ticket at http://support.xlinesoft.com sending a URL to your pages along with instructions on reproducing this error.