This topic is locked

Redirect to Add Detail Page after Add Master Record

11/9/2008 5:03:08 PM
PHPRunner General questions
E
erago author

I want to provide the following function.
If a User adds a Record to a Master Table, then after a Successful record add, then redirect to Detail Add page,
Using the following Event/Add page/ After record added
// Parameters:

// $values - Array object.

// Each field on the Add form is represented as a 'Field name'-'Field value' pair

// $keys - Array object with added record key column values
//** Redirect to another page ****

header("Location: _Product_Details_add.php");

global $conn;

$strSQLInsert = "insert into ".$strTableName." Product_Number='".$keys["Product_Number"]."'";

db_exec($strSQLInsert,$conn);

exit();
This code does not create and error message, but does not assign the correct "Product_Number" or (Master_Table_ID) to the detail table.

Instead it seems so be assigning the detail record to the Master Record before the one that was just added.
have also tried the following code with the same result.
//** Redirect to another page ****

header("Location: _Product_Details_add.php");

" Product_Number='".$keys["Product_Number"]."'";

exit();
anyone know what I am missing?

J
Jane 11/10/2008

Hi,
I suppose you just need to redirect to the details record and save master key in the session variable.

Here is a sample:

$_SESSION["_Product_Details_mastertable"] = "MasterTableName";

$_SESSION["_Product_Details_masterkey1"] = $keys["Product_Number"];

header("Location: _Product_Details_add.php");

exit();

E
erago author 11/10/2008

Hi,

I suppose you just need to redirect to the details record and save master key in the session variable.

Here is a sample:


I gave that a try, and I'm not sure I understand completely.

In Events Table=_Products/add page/ after record added. write this code-
$_SESSION["_Product_Details_mastertable"] = "MasterTableName";

$_SESSION["_Product_Details_masterkey1"] = $keys["Product_Number"];

header("Location: _Product_Details_add.php");

exit();
which gives the new detail record a "Product_Number" value =NULL (Incorrect)
also tried "_Products" in place of "MasterTableName"

which gives the new detail record a "Product_Number" value =0 (also Incorrect)

do I need to put a line in another event to load the $keys["Product_Number"] maybe in Events/Table=_Product_Details/addOnLoad or Add page: Before process ?
Again Thanks you for your help.

J
Jane 11/11/2008

Hi,
make sure $_SESSION variables are filled.

For example print it in the Add page: Before process event:

echo "_Product_Details_mastertable: ".$_SESSION["_Product_Details_mastertable"];

echo "_Product_Details_masterkey1: ".$_SESSION["_Product_Details_masterkey1"];


Also check that default value of Product_Number is set up as $_SESSION[$strTaleName."_masterkey1"] on the "Edit as" settings dialog on the Visual Editor tab.

E
erago author 11/12/2008

Hi,

make sure $_SESSION variables are filled.

For example print it in the Add page: Before process event:
Also check that default value of Product_Number is set up as $_SESSION[$strTaleName."_masterkey1"] on the "Edit as" settings dialog on the Visual Editor tab.


Still having Issue's with getting the correct masterkey1/Product_ID processed
Started redirecting to the list page instead of the add page, to see what it was trying to assign the masterkey1/Product_ID Value.
Using the following code ( show's which record via master table info at top of page)

$_SESSION["_Product_Details_mastertable"] = "MasterTableName";

$keys=$_SESSION["_Product_Details_masterkey1"];

header("Location: _Product_Details_list.php?mastertable=_Tags&masterkey1=$keys");

exit();
and using your:

in the Add page: Before process event:

echo "_Product_Details_mastertable: ".$_SESSION["_Product_Details_mastertable"];

echo "_Product_Details_masterkey1: ".$_SESSION["_Product_Details_masterkey1"];


now here is what is happening,

If it Echo's the .$_SESSION["_Product_Details_masterkey1"] at "142"

It carries the value of "142" to the Location: _Product_Details_list.php?mastertable=_Tags&masterkey1=$keys" (the $keys value =142) so far so good.

but here is the problem when it saves the new Product Record(Master Record for Product_Details) the true value for .$_SESSION["_Product_Details_masterkey1"] was really "143"
sometimes it's a great difference between the two values.
at any rate it is failing to capture or use the true masterkey1/ Product_ID value.

I see it is echoing a value that the database hasn't assigned it yet, it is an auto increment value and is assigned when the record is added not before, right?
how do you capture a value in the record that was just recorded?

J
Jane 11/13/2008

It's difficult to tell you what's happening without seeing actual files.
Please publish your project on Demo Account and send to support@xlinesoft.com a URL to your pages along with instructions on reproducing this error.

I'll find what's wrong with your project inspecting it at Demo account site.