This topic is locked
[SOLVED]

 Inserting a record into another table

12/31/2018 9:29:08 PM
PHPRunner General questions
S
steveng author

Hello...
I'm a new PHPrunner user working on a order taking/tracking app for a local non-profit organization and I'm stuck. I'm trying to insert a record into another table from the client edit page, into the orders table using a custom button server event. I've tried using examples found in the manual, examples from support and I simply can't get them to work. Here are the two code snippets:
// Insert a record into table

$data = array();

$data["firstname"] = firstname;

$data["middlename"] = middlename;

$data["lastname"] = lastname;

DB::Insert("orders", $data );
This code does nothing, no record is added, nor do I get any errors using chrome developers debugger. I also tried:
global $dal;
$data = $dal->Table("orders");
$data->firstname = $record["firstname"];

$data->middlename = $record["middlename"];

$data->lastname = $record["lastname"];
$data->Add();
I have the same exact results as the above sample. I would very much appreciate any insight to whats going on.
Thanks,

  • Steven

T
thamestrader 1/3/2019



Hello...
I'm a new PHPrunner user working on a order taking/tracking app for a local non-profit organization and I'm stuck. I'm trying to insert a record into another table from the client edit page, into the orders table using a custom button server event. I've tried using examples found in the manual, examples from support and I simply can't get them to work. Here are the two code snippets:
// Insert a record into table

$data = array();

$data["firstname"] = firstname;

$data["middlename"] = middlename;

$data["lastname"] = lastname;

DB::Insert("orders", $data );
This code does nothing, no record is added, nor do I get any errors using chrome developers debugger. I also tried:
global $dal;
$data = $dal->Table("orders");
$data->firstname = $record["firstname"];

$data->middlename = $record["middlename"];

$data->lastname = $record["lastname"];
$data->Add();
I have the same exact results as the above sample. I would very much appreciate any insight to whats going on.
Thanks,

  • Steven


Hi Steven,

I too volunteer (work) for a charity (a Foodbank in the UK) and my application has a similar requirement; to insert a record into the Vouchers table for a client to receive a food parcel.
Have you considered using the Master/Detail relationship to manage this?
The way I did this is pretty much out of the box stuff. I have two tables Person (the Master) and Voucher (the detail), the master/detail feature joins them together using the key of the master so it has to also exist as a field on the detail. In use the process is as follows:
Search for the client of the Person table - if not found then add them, when found it displays the details on the list page with a link to the Vouchers (details), click on the link to display the Vouchers/Orders, click the Add New Button to insert into the Vouchers/Orders (detail).
The beauty of the Master/Detail design is that the only data duplicated on the Detail from the Master is the master ID key field. All my tables have an auto-increment ID field which is the unique key field and purely for linking between tables, the real user oriented key fields like address, first name, last name etc are defined as key fields and used in searches as you would expect. This means that in the event of data changing on the master, for example address, the detail records are unaffected as they do not contain the address data.
This is all out of the box PHPRunner and works well, of course you can then 'tart up' the pages as required.....
Hope this helps

A
ayctech 1/3/2019

$sql = "INSERT INTO new_plantel_instructores (id_instituto, id_persona,fecha_insercion) values ($id_instituto, ".$values['id_persona'].",'".$fecha_actual."')";

CustomQuery($sql);

Sergey Kornilov admin 1/3/2019

This is the code that worked:



$data = $button->getCurrentRecord();

$record = array();

$record["firstname"] = $data["firstname"];

$record["middlename"] = $data["middlename"];

$record["lastname"] = $data["lastname"];

$record["client_no"] = $data["client_no"];

DB::Insert("orders", $record );


More info:

https://xlinesoft.com/phprunner/docs/button_getcurrentrecord.htm

https://xlinesoft.com/phprunner/docs/db_insert.htm