This topic is locked
[SOLVED]

 How to insert $_SESSION values into the auto insert field on Excel Import

7/16/2016 10:11:18 AM
PHPRunner General questions
A
Abul author

I have an issue getting autoinsert field to be inserted with $_SESSION[“UserID”] values on Excel Import. My project is with phprunner 8.1v. Here is my table structure
“trld”

ID, VAR, UPBY
Excel file structure: My excel sheet has only VAR field with data. ID field should be autoincrement. UPBY field is auto-insert field with $_SESSION["UserID"].
Logic: when I add or import new VAR data then the UPBY field in the table should be auto-inserted with $_SESSION[“UserID”] value.
Action so far done:

  1. After Successful login event on Login Page
    $_SESSION[“UserID”]=$data[“UserID”]; saved UserID in the SESSION.


2.Added following code in Before Record Added event on Add Page

$Values[“UPBY”]=$_SESSION[“UserID”];


3.Added following code in Before Insert Record event on Import Page

$Values[“UPBY”]=$_SESSION[“UserID”];


Result: Add page event works perfectly without any issue. But the Import page through error without import any records. Again if I don’t use this code on Import Page event then all the records are imported correctly without inserting autoinsert field UPBY in the table.
Testing: when I echoed the same SESSION var on Import page as Snippet, it shows the UserID values.
What is my wrong?
Thanks in Advanced.

romaldus 7/16/2016



I have an issue getting autoinsert field to be inserted with $_SESSION["UserID"] values on Excel Import. My project is with phprunner 8.1v. Here is my table structure
"trld"

ID, VAR, UPBY
Excel file structure: My excel sheet has only VAR field with data. ID field should be autoincrement. UPBY field is auto-insert field with $_SESSION["UserID"].
Logic: when I add or import new VAR data then the UPBY field in the table should be auto-inserted with $_SESSION["UserID"] value.
Action so far done:

  1. After Successful login event on Login Page
    2.Added following code in Before Record Added event on Add Page
    3.Added following code in Before Insert Record event on Import Page
    Result: Add page event works perfectly without any issue. But the Import page through error without import any records. Again if I don't use this code on Import Page event then all the records are imported correctly without inserting autoinsert field UPBY in the table.
    Testing: when I echoed the same SESSION var on Import page as Snippet, it shows the UserID values.
    What is my wrong?
    Thanks in Advanced.


You don't have to load session userid in after succesully login event. It's PHPRUNNER default session for username of currently logged-on user.

Try to replace

$_SESSION["UserID"]=$data["UserID"];

with

$_SESSION["any_name"]=$data["UserID"];

and use it in before insert record event in import page

A
Abul author 7/16/2016



You don't have to load session userid in after succesully login event. It's PHPRUNNER default session for username of currently logged-on user.

Try to replace

$_SESSION["UserID"]=$data["UserID"];

with

$_SESSION["any_name"]=$data["UserID"];

and use it in before insert record event in import page


Thank you so much romuldus for your quick reply. However, this tip does not work for me. Very interesting is that when I rebuild this same project in phpr 7.1v then works fine but it does not work with phpr 8.1v. I am not sure what is wrong. Please help me again. Thanks again.

romaldus 7/16/2016

I think this is strange. I am curious about your case, so i made a sample project.

In after successful login event i use the following:

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


in before record is inserted (import page) :



$values['upload_by'] = $_SESSION["UserID"];

$values['user_id'] = $_SESSION["UID"];


Make sure userid field in your table is integer and update your phprunner 81 to latest build

Tested in PHPRUNNER 8.1 64bit Latest version (build 25268)
My User table structure:



picture hosting
Screenshot of my excel data



img host
Screenshot after import data. Green circle is both userID and username of logged user (inserted from session)


img host

A
Abul author 7/17/2016



I think this is strange. I am curious about your case, so i made a sample project.

In after successful login event i use the following:

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


in before record is inserted (import page) :



$values['upload_by'] = $_SESSION["UserID"];

$values['user_id'] = $_SESSION["UID"];


Make sure userid field in your table is integer and update your phprunner 81 to latest build

Tested in PHPRUNNER 8.1 64bit Latest version (build 25268)
My User table structure:



picture hosting
Screenshot of my excel data



img host
Screenshot after import data. Green circle is both userID and username of logged user (inserted from session)


img host



Thank you ramaldus for your time. Its working now. Thanks.