Hi all! Thanks for being there.
I’m trying to write a procedure that will collect a person’s name & contact info, then store a bunch of related items in an array. When they’re done adding items, I want to save the data to a couple of tables in a MySQL db.
My problem is the Array with the ‘related items’ vanishes.
I’m saving the ‘owner’ info in variables like $_SESSION[‘fieldname’] where fieldname = the input from the form. That’s all cool, it stays where it should and life is good.
When I establish the array for the related items, however, I can’t go very far before it’s missing and I get the “Undefined index” message.
Here’s a quick & dirty rundown of what I’m doing:
At the top of the script I have a
[php]<?
session_start();
//Then this tells us what we’re doing each time we come back to the script…
if (!isset($_SESSION[‘action’]))
{
$_SESSION[‘action’] = “getpersoninfo”; // The first thing to do is get personal info
}
else
{
$_SESSION[‘action’] = $_REQUEST[‘action’]; // Do whatever is passed with the next ‘call’ to this same script
}
// Works fine up to here
…
if (!isset($_ITEMS)) // Establish the Array for Items. IS THIS RIGHT?
{
$_ITEMS[] = array();
$_ITEMS[0] = “x”;
echo $_ITEMS[0];
}
// It will display x here (on the first pass) no problem.
…
// If after filling in the Personal Info, and entering an Item Number on forms within the script (not shown here), the site user says “yes, I want this”, then this should commit the item to the array, right?
if ($_REQUEST[‘action’] = “additem”)
{
$_ITEMS[] = $thisitem; // I would think this would add the $thisitem to the $_ITEMS array - right?
}
// Unfortunately, the array $_ITEMS is gone by the second time we’re coming down the script - so we can’t append to it!
switch $_SESSION[‘action’]
{
case “getpersonalinfo”:
// code for the form to get info, with a form action to come back to this script ?action=getitems
break;;
case “getitems”:
// code for the form to get an item code with a form action to come back to this script ?action=confirm
break;;
case “confirm”;
/* code to check that the item exists in the database (yes we’re hooked up to the db & all error checking is handled). Then there are links to allow them to
1)confirm it’s what they want & add more, or
2)confirm it’s what they want & done, or
3)bail out & try again.
*/
break;;
/* If they choose either of the first two options - the script calls itself ?action=additem - meeting the If() earlier in the script … but sadly, the array is gone, so no item is ADDED.
*/
…
}
?>[/php]
Any help or insights you can provide would be GREATLY appreciated!!!
**MOD EDIT - Added [ php ] tags for readablity.