This topic is locked

Add record, with data from another table.

7/6/2010 7:48:34 PM
PHPRunner General questions
L
lucas author

Hi,
I'm trying to add a new record, and at the same time, pull some information from another table rather than having the user fill it in again. Can someone direct me as to where I'm going wrong?
Add Page: Before Display
global $conn;

$strSQLSelect = "SELECT Emp_FirstName, Emp_LastName, Emp_EmailAddress, Emp_BranchID FROM Employees WHERE Emp_Username = '".$_SESSION["UserID"]."'";

$rsSelect = db_query($strSQLSelect,$conn);

$data=db_fetch_array($rsSelect);
$xt->assign("Emp_FirstName", $data["Emp_FirstName"]);

$xt->assign("Emp_LastName", $data["Emp_LastName"]);

$xt->assign("Emp_EmailAddress", $data["Emp_EmailAddress"]);

$xt->assign("Emp_BranchID", $data["Emp_BranchID"]);
PHPRunner 5.2 build 5482

Sergey Kornilov admin 7/7/2010

You need to setup default values for those fields to session variable.
i.e. field "Emp_FirstName", default value $SESSION["Emp_FirstName"]
BeforeDisplay event:

$_SESSION["Emp_FirstName] = $data["Emp_FirstName"];
Full BeforeDisplay event code:



global $conn;

$strSQLSelect = "SELECT Emp_FirstName, Emp_LastName, Emp_EmailAddress, Emp_BranchID FROM Employees WHERE Emp_Username = '".$_SESSION["UserID"]."'";

$rsSelect = db_query($strSQLSelect,$conn);

$data=db_fetch_array($rsSelect);
$_SESSION["Emp_FirstName] = $data["Emp_FirstName"];

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

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

$_SESSION["Emp_BranchID] = $data["Emp_BranchID"];
L
lucas author 7/7/2010



You need to setup default values for those fields to session variable.
i.e. field "Emp_FirstName", default value $SESSION["Emp_FirstName"]
BeforeDisplay event:

$_SESSION["Emp_FirstName] = $data["Emp_FirstName"];
Full BeforeDisplay event code:



global $conn;

$strSQLSelect = "SELECT Emp_FirstName, Emp_LastName, Emp_EmailAddress, Emp_BranchID FROM Employees WHERE Emp_Username = '".$_SESSION["UserID"]."'";

$rsSelect = db_query($strSQLSelect,$conn);

$data=db_fetch_array($rsSelect);
$_SESSION["Emp_FirstName] = $data["Emp_FirstName"];

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

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

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



thanks!

appears this error
syntax error, unexpected '"', expecting T_STRING or T_VARIABLE or T_NUM_STRING in line 8
starting this part of the code
$_SESSION["Emp_FirstName] = $data["Emp_FirstName"];

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

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

$_SESSION["Emp_BranchID] = $data["Emp_BranchID"];
created to better understand other tables.
Table 1: client

Fields: f_id f_client f_product f_func
Table 2: Pay

Fields: f_id f_client f_product f_func f_date f_value f_phone f_number
really would not want to retype what I typed in table 1

f_id f_client f_product f_func
but really need to reenter this information

D
Dale 7/7/2010

A quick stab it for you.

Note your section where the error begins.

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

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

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

$_SESSION["Emp_BranchID] = $data["Emp_BranchID"];
should be ( note the " missing in the $_SESSION variables.

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

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

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

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

L
lucas author 7/7/2010



A quick stab it for you.

Note your section where the error begins.

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

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

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

$_SESSION["Emp_BranchID] = $data["Emp_BranchID"];
should be ( note the " missing in the $_SESSION variables.

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

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

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

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


Thanks!
the error no longer appears.
but when I type the name of the client f_client not complete the rest of the data
created to better Understand other tables.
Table 1: client

Fields: f_id f_client f_product f_func
Table 2: Pay

Fields: f_id f_client f_product f_func f_date f_value f_phone f_number
really would not want to retype what I typed in a table

f_id f_client f_product f_func
But Really Need to reenter this information

A
ann 7/8/2010

Lucas,
select f_product, f_func fields as dependent dropdowns (from the field f_client).

In order to do it check 'How to setup dependent dropdown boxes on Edit/Add pages' article:

http://xlinesoft.com/phprunner/php-database.htm

L
lucas author 7/8/2010



Lucas,
select f_product, f_func fields as dependent dropdowns (from the field f_client).

In order to do it check 'How to setup dependent dropdown boxes on Edit/Add pages' article:

http://xlinesoft.com/phprunner/php-database.htm


Thanks Ann. We have been using dependent dropdown features .

i have some reason to avoid using it in particular situation, for example when working with a large database, lookup more than 100000 record (ProductID) using dependent dropdown with low bandwidth connection sometimes pain.
if possible id like to enter and pull those fields and others that if you need to define in the future
I've seen some requests in the forum like this but do not even have one with a solution.

thanks again

A
ann 7/9/2010

Lucas,
unfortunately, there is no other way fill in values on fly.

romaldus 7/13/2010



Lucas,
unfortunately, there is no other way fill in values on fly.


lucas, you can try my solution here :

http://www.asprunner.com/forums/topic/14767-update-a-field-from-another-table/