This topic is locked
[SOLVED]

Can Not Return "id" (auto increment value) after custom add

12/5/2021 2:56:19 PM
PHPRunner General questions
U
ustunsoz author

I am using Sql View with join as database table, tharefore I can not use original table in add edit pages.

I have used custom add and After record added events for to add the record to the both tables. However in custom add primary key is auto increment value and I have to use in next event to add in second table but the value is not returning to the After add event. How can I obtain the value aftter custom add?

Code for Custom add:

$data = array();
$data["id"]=$keys["id"];
$data["Company"]=$values["Company"];
DB::Insert("contact", $data );

Code for After record added:

$data = array();
$data["contact_id"] = $keys["id"];
$data["contact_status"] = $values["contact_status"];
DB::Insert("owner", $data );
U
ustunsoz author 12/5/2021

I forgot the add last line in Custom event code:

$data = array();
$data["id"]=$keys["id"];
$data["Company"]=$values["Company"];
DB::Insert("contact", $data );
return false;
J
John 12/5/2021

Use last insert function DB::LastId() from database. See https://xlinesoft.com/phprunner/docs/db_lastid.htm

John

U
ustunsoz author 12/5/2021

Thanks John,

I have alrady tried as follow;

$data = array();
$data["id"]=$keys["id"];
$data["Company"]=$values["Company"];
DB::Insert("contact", $data );
$_SESSION['comp_id'] = DB::LastId("tsu_contact", $data );

end then After record added:

$data = array();
$data["contact_id"] = $_SESSION['comp_id'];
$data["contact_status"] = $values["contact_status"];
DB::Insert("owner", $data );
unset($_SESSION['comp_id']);
return false;

The first record posting to 1st table but, second table dont get any insert and I ma not getting any error message too

U
ustunsoz author 12/5/2021

Sorry in first code the last line was typo, the actual one as follow:

$_SESSION['comp_id'] = DB::LastId();

U
ustunsoz author 12/6/2021

I have found the issue that not related to above code, related to table structure! (One of the field expecting a default value)
The code not returning an error message, therefore it took sometime to investigate.

Now the above code doing the job