This topic is locked
[SOLVED]

Insert record in another table after registration

4/6/2022 10:34:53 AM
PHPRunner General questions
A
alfonso authorDevClub member

I want to insert a record into a table after the record is committed. If I add a fixed value in a field everything is correct. But I want to add the ID or the values of the records table and I can't do it with this code. It seems that it does not correctly collect the fields of the registry table
I am working with the jobusers table of the template

This code works fine
function AfterSuccessfulRegistration(&$userdata, $pageObject)
{
$data2 = array();
$data2["nombre"] = "alfonso";
DB::Insert("b_curriculum", $data2 );
;

}

But if I want to insert ID value or ID session I don't get:

function AfterSuccessfulRegistration(&$userdata, $pageObject)
{
$data2 = array();
$data2["cv_id"] = $userdata["ID"];
$data2["nombre"] = "alfonso";
$data2["email"] = $userdata["email"];
DB::Insert("b_curriculum", $data2 );
;

}

I also try this:

$_SESSION["ID1"] = $data["ID"];

$data = array();
$data["cv_id"] = $_SESSION["ID1"];
DB::Insert("b_curriculum", $data );

Any idea .Thanks

Sergey Kornilov admin 4/7/2022

Instead of your code in AfterSuccessfulLogin event use the following:
var_dump($userdata);

Let us know what it prints.

A
alfonso authorDevClub member 4/7/2022

I get this:
array(5) { ["Username"]=> string(4) "aga2" ["Password"]=> string(9) "Alfon1862" ["Email"]=> string(24) "fact@gesdinet.com" ["member_level"]=> string(1) "1" ["active"]=> int(0) }

A
alfonso authorDevClub member 4/7/2022

With this code I get to insert record:

$data2 = array();
$data2["nombre"] = "alfonso";
$data2["email"] = $userdata["Email"];
DB::Insert("b_curriculum", $data2 );

but I need to insert ID session or ID field from jobusers table. This is the table I use to register

Sergey Kornilov admin 4/7/2022

It apepars that your ID field is not available in $userdata array. This may happen for a couple of reasons.

  1. Make sure that ID field is a part of the SQL query of the login table
  2. Make sure that this ID field is autoincrement

A
alfonso authorDevClub member 4/8/2022

If I add the ID field from the jobusers table to the register form then it works.
The problem is that I don't want it to be an editable field, because it is an autonumeric field. But that field is not filled only and its value is null. I I don't fill manually this field I get in vardump: ["ID"]=> string(0)

Sergey Kornilov admin 4/8/2022

In this case, I guess that you can perform a SQL select from the login table based on the username for instance, and retrieve new ID this way.

A
alfonso authorDevClub member 4/11/2022

Thanks. How can I see session ID? Or save it in a field?

A
alfonso authorDevClub member 4/13/2022

I've got it with this code:

$data2 = array();
$data2["nombre"] = $userdata["nombreapellidos"];
$data2["email"] = $userdata["Email"];
$data2["nif"] = $userdata["nif_user"];
DB::Insert("b_curriculum", $data2 );

But now what I want is that depending on the group or member_level save the data in a table or in another table. I try this

if( $_SESSION["GroupID"]=="1") {

$data2 = array();
$data2["nombre"] = $userdata["nombreapellidos"];
$data2["email"] = $userdata["Email"];
$data2["nif"] = $userdata["nif_user"];
DB::Insert("b_curriculum", $data2 );
}

if( $_SESSION["GroupID"]=="2") {

$data2 = array();
$data2["nombre"] = $userdata["Email"];
$data2["email"] = $userdata["Email"];
$data2["nif"] = $userdata["nif_user"];
$data2["member_level"] = $userdata["member_level"];
DB::Insert("b_curriculum_new", $data2 );
}

But I don't get it. I also try with $userdata

if( $userdata["member_level"] = 1) {

$data2 = array();
$data2["nombre"] = $userdata["nombreapellidos"];
$data2["email"] = $userdata["Email"];
$data2["nif"] = $userdata["nif_user"];
DB::Insert("b_curriculum", $data2 );
}

if( $userdata["member_level"] = 1) {

$data2 = array();
$data2["nombre"] = $userdata["Email"];
$data2["email"] = $userdata["Email"];
$data2["nif"] = $userdata["nif_user"];
$data2["member_level"] = $userdata["member_level"];
DB::Insert("b_curriculum", $data2 );
}

Any idea?. Thanks
A
alfonso authorDevClub member 4/13/2022

I think I got it with:
if( $userdata["member_level"] == 1) {