This topic is locked
[SOLVED]

 Issue With Getting Field Value In Php Code Snippet

7/10/2013 12:42:59 PM
PHPRunner General questions
N
nohope4you author

I have the following code in a php snippet on an Edit page hoping that it would output the Company field value. My details on my database are as follows
Connection Type: SQL Server

Table Name: dbo.Invoices2

Field Name 1: Invoice#

Field Name 2: Company
Did I write this the way it is supposed to be written? When I have it load on my edit page, it breaks with no error message.



global $dal;

$tblInvoices = $dal->Table("dbo.Invoices2");

$rs = $tblInvoices->Query("Invoice#=".$_REQUEST["editid1"]."");

$data = db_fetch_array($rs);

$CompanyID = $data["Company"];

echo $CompanyID;


I've also tried this:



global $conn;

$strSQL = "select invoice#,company from dbo.invoices2 where invoice#=".$_REQUEST["editid1"]."";

$rs = db_query($strSQL,$conn);

$data = db_fetch_array($rs);

$Company = $date(company);

echo $Company;


What I'd like to use this for is to change the background image for the edit page based on the company name. I already have this working by creating a custom view button from the list page that has the company value built into the URL, but I'd like to get this accomplished without the url variable so no matter how the edit page is loaded or linked to, its showing the correct background for that company.

Sergey Kornilov admin 7/10/2013

You may need to wrap field name Invoice# with square brackets to screen the "bad" character:

select [invoice#],company from dbo.invoices2 where [invoice#]=...


Another thing - on the Edit page you can use ProcessValues event to access the value of any field:

http://xlinesoft.com/phprunner/docs/process_record_values.htm
You can simply save the value of any field in session variable and later use this variable in your PHP code snippet.

N
nohope4you author 7/10/2013

Thanks for the reply. That made me think of setting up a Session variable for the company name in the 'Before display' event area and that worked perfectly.



You may need to wrap field name Invoice# with square brackets to screen the "bad" character:

select [invoice#],company from dbo.invoices2 where [invoice#]=...


Another thing - on the Edit page you can use ProcessValues event to access the value of any field:

http://xlinesoft.com/phprunner/docs/process_record_values.htm
You can simply save the value of any field in session variable and later use this variable in your PHP code snippet.