This topic is locked

insert record before page displays

3/10/2012 12:35:53 PM
PHPRunner General questions
S
stiven author

Hello everyone,
I have a question, I have a button on an edit page that redirects the user to another edit page on a different table. my question is, is it possible to insert a record when the user clicks on the button before the new page is displayed?
example..
--edit page --
contract_edit.php?editid1=123
button = <A class=runner-button href="addendum_one_edit.php?editid1=123">Addendum One</A>
but actually on table addendum_one there is no record "123" yet. it needs to be inserted when the user clicks the button so that there will be something to be displayed on the edit page.
I hope this makes sense
Thanks

W
wildwally 3/10/2012

If there is no record 123 would it not be better to navigate to the add page for that table?
I know what your asking is possible, but I'm still a little fuzzy on what exactly your wanting to pass.

H
hernanccs 3/11/2012

you might be able to do it by adding something like this in the to before display event on the target page
global $conn;

$strSQLInsert = "insert into TABLEA (FieldA, FieldB, FieldC) values ('".$values["FieldA"]."','".$values["FieldB"]."','".$values["FieldC"]."')";

db_exec($strSQLInsert,$conn);
you should create an extra field on the second table to include the key from the first table
TableA

-RecordIDA (i wouldnt use this as key on second table, if u do that, you will get errors if you press the button more than once on the first view page)

-FieldA

-FieldB
TableB

-RecordIDB (autoincrement)

-FieldA

-FieldB

-FieldC (to store the RecordIDA)
Then if you need to link the tables you should link RecordIDA from TableA to FieldC on TableB