This topic is locked

passing variables from add page to view page

5/22/2007 1:22:27 AM
PHPRunner General questions
E
evan_ad2000 author

Hi,
I was wondering if anyone can tell me how I can pass variables from an add page in to a view page? The add page acts like a form and doesnt add anything to the database. I was to some of the information from the form into a view page so the user can print it out.
Thanks,

Evan

Alexey admin 5/22/2007

Evan,
save values into $_SESSION array or pass them in URL string:

header("..._view.php?var1=".$values["Field1"]."&var2=".$values["Field2"]);

exit();

E
evan_ad2000 author 5/28/2007

Evan,

save values into $_SESSION array or pass them in URL string:


Hi,
I failed to mention that the view page is just a custom view which does not relate to any table data. I have tried the following but nothing changes:
$_SESSION['send_customer'] = $values['Customer Name'];

$_SESSION['send_part'] = $values['Product'];

$_SESSION['send_serial'] = $values['Serial Number'];
//** Redirect to another page ****

header("Location: _Send_Receive_Report_view.php?var1=".$values['Customer Name']."&var2=".$values['Product']."&var3=".$values['Serial Number']);

exit();
I have also tried:
$_SESSION['send_customer'] = $values['Customer Name'];

$_SESSION['send_part'] = $values['Product'];

$_SESSION['send_serial'] = $values['Serial Number'];
//** Redirect to another page ****

header("Location: _Send_Receive_Report_view.php?var1=".$_SESSION['Customer Name']."&var2=".$_SESSION['Product']."&var3=".$_SESSION['Serial Number']);

exit();
Both did not have any results.
Thanks,

Evan

J
Jane 5/29/2007

Evan,
where do you use this code?

E
evan_ad2000 author 5/29/2007

Evan,

where do you use this code?


Here:
function BeforeAdd(&$values)

{

global $conn;

// Parameters:

// $values - Array object.

// Each field on the Add form represented as 'Field name'-'Field value' pair
$_SESSION['send_customer'] = $values['Customer_ID'];

$_SESSION['send_part'] = $values['Product'];

$_SESSION['send_serial'] = $values['Serial_Number'];
//Find Transaction ID from Transaction

$strTID = "select `ID` from `_transactio`n where `Transaction_Name` = \"".$values['Type']."\"";

$rsTID = db_query($strTID, $conn);

$dataTID = db_fetch_numarray($rsTID);

$tID = $dataTID[0];
//Find Product ID from RA Products

$strPID = "select `product_id` from `ra_products` where `part_number` = \"".$values['Product']."\"";

$rsPID = db_query($strPID, $conn);

$dataPID = db_fetch_numarray($rsPID);

$pID = $dataPID[0];
//Retrieve Last Items ID

$strItemID = "select max(item_id) from `items`";

$rsItem = db_query($strItemID, $conn);

$dataItem = db_fetch_numarray($rsItem);

$itemID = ++$dataItem[0];
//split up all serials inside text area into array

$serialArray = explode("\n", $values["Serial_Number"]);
//trim strings inside array

for($i = 0; $i < count($serialArray); $i++)

{

trim($serialArray[$i]);

}
for($i = 0; $i < count($serialArray); $i++)

{

//try to find item_id in Items table

$strSearchID = "select `item_id` from `items` where `serial_number` = \"" . $serialArray[$i] . "\"";

$rsSearchID = db_query($strSearchID, $conn);

$dataSearchID = db_fetch_numarray($rsSearchID);

$searchID = $dataSearchID[0];
if($searchID)

{

//if item_id exist, only add new entry to items transactions

$strSQLInsert = "insert into itemtransaction (item_id, date, transaction_id, customer_id, location_name) values (".$searchID.",\"".now()."\", '".$tID."', '".$values['Customer_ID']."', '".$values['Location_Name']."')";

db_exec($strSQLInsert,$conn);

}

else

{

//if item_id does not exist, add new entry into Items and items transactions

$strInsertSerial = "insert into items (item_id, product_id, serial_number) values (" . $itemID . ", " . $pID . " ,\"" . $serialArray[$i] . "\")";

db_exec($strInsertSerial, $conn);

$strSQLInsert = "insert into itemtransaction (item_id, date, transaction_id, customer_id, location_name) values (".$itemID.",\"".now()."\", '".$tID."', '".$values['Customer_ID']."', '".$values['Location_Name']."')";

db_exec($strSQLInsert,$conn);

$itemID++;

}

}
//** Redirect to another page ****

header("Location: _Send_Receive_Report_view.php?var1=".$_SESSION['Customer ID']."&var2=".$_SESSION['Product']."&var3=".$_SESSION['Serial Number']);

exit();
return false;
// return true if you like to proceed with adding new record

// return false in other case
}
Cheers,

Evan

J
Jane 5/30/2007

Evan,
you code looks good.

You can access to Customer ID, Product and Serial Number values on the View page (for example on the ViewOnLoad event) using $_REQUEST["var1"], $_REQUEST["var2"] and $_REQUEST["var3"] variables.

E
evan_ad2000 author 6/1/2007

Evan,

you code looks good.

You can access to Customer ID, Product and Serial Number values on the View page (for example on the ViewOnLoad event) using $_REQUEST["var1"], $_REQUEST["var2"] and $_REQUEST["var3"] variables.


Hi,
Thanks for the hint. Var 3 happens to be a list of serial numbers, instead of having them in one line, how can i put each serial number on a separate line?
Thanks,

Evan

J
Jane 6/1/2007

Evan,
to split list of numbers use explode PHP function:

http://php.net/manual/en/function.explode.php

E
evan_ad2000 author 6/2/2007

Evan,

to split list of numbers use explode PHP function:

http://php.net/manual/en/function.explode.php


I did try to use that. In the custom code i have this code,
$str = "";

$serialStr = $_SESSION['send_serial'];

$serialArray = explode(" ", $serialStr);

for($i = 0; $i < count($serialArray); $i++)

{

$str = $str . "</br>" . $serialArray[$i];

}

$value = $str;
But this did not work, I also tried to replace "</br>" with "\n" but that didn't work as well.
Anyone has any ideas?
Cheers,

Evan