mljonzs
Posts: 124
|
| Posted: 06/13/2006, 6:40 AM |
|

I feel rather dumb asking this as it seems like I am just missing something rather obvious, but I have given up. I am creating a simple online survey for users to complete. All the responses are currently being stored in a single database table (SQL Server if it matters??).
I want to break it up into four separate web pages with a NEXT button on the first 3 pages and a complete on the last page. I'd like for the NEXT button on the first page to create the record and have the remaining three pages just update that record but I can't seem to get this to happen for me and I know I'm just doing something wrong. The key for the table is an autogen number but I haven't figured out how to grab the key after the record has been inserted and pass it to the next page so that page can do an update. We use ASP (not .NET)
Please help me out! Any information/suggestions are appreciated!
Michelle Jones
_________________
What does not begin WITH God, will end in failure!
|
 |
 |
jsmonkey
Posts: 39
|
| Posted: 06/13/2006, 7:07 AM |
|
Check out the Multi-Step Registration example at http://examples.codecharge.com It has a lot of tips and sounds exactly like what you need. Give it a run though and feel free to ask more questions.
_________________
-J |
 |
 |
DonB
|
| Posted: 06/13/2006, 6:44 PM |
|
My preference is to capture the form values and save them in an array, then
put the array into a session variable. At the end of the sequence, stuff
the array values into the database:
In the button Click (presumed to be named "Button_Insert" in this example
and the button action is left empty):
$myArray = unserialize(CCGetSession("myArray"));
foreach (myGrid->FormParameters as $key => $value) {
if ($key != "Button_Insert")
$myArray[$key] = $value;
CCSetSession("myArray", serialize($myArray));
}
This gets any existing instance of the session var 'myArray', and tacks on
parameters from the form. Do this as many times as you need to, for as many
'steps' in your multi-step sequence. Because you can't store an array
directly into the Session, I serialize it (and then have to unserialize it).
A serialized array CAN be stored in a session variable.
When the array is complete, that is, all steps are done, the array contains
an element for each field for which there was input provided. Now, you just
have to transform it into an INSERT query:
$myArray = unserialize(CCGetSession("myArray"));
$cols = "";
$values = "";
$sep = "";
foreach ($myArray as $key => $value) {
$cols .= $sep . $key;
$values .= $sep . $value; # Caution, strings would need to be enclosed
in apostrophes
$sep = ",";
}
$sql = "INSERT tablename ($cols) VALUES ($values)";
$db->query($sql);
In actual practice, I define all the field names on the forms to be the
corresponding database table column name. To deal with the 'strings need
apostrophes' issue, I've used a prefixe letter (n for number, s for string,
d for date, etc) on the fieldnames so I know which ones need the
apostrophes. I just chop the first letter off '$key' and use what's left as
the column name.
OK, I know that's PHP code, not ASP. But it's a straightforward translation
anyhow (er, with possible exception of serialize and unserialize). CAVEAT:
This is excerpted from some real code but I just typed it in, so be prepared
for it to not 'just work as-is'. You may have to correct a typo or
something. Use what I provided only as a guide.
Instead of the button Click event, you may prefer to leave the button action
as "Insert", "Update" or "Delete" and then use the Validate or Before
Insert, Before Update, Before Delete events - depending on your
requirements. You would want to execute
myGrid->ds->CmdExecution = false
to cancel out of the form insert/update/delete, if you use those other
events. I suggest leaving the button action blank, so that only the
(server) Click event fires.
--
DonB
http://www.gotodon.com/ccbth
"mljonzs" <mljonzs@forum.codecharge> wrote in message
news:2448ec0637971b@news.codecharge.com...
> 
> I feel rather dumb asking this as it seems like I am just missing
something
> rather obvious, but I have given up. I am creating a simple online
survey for
> users to complete. All the responses are currently being stored in a
single
> database table (SQL Server if it matters??).
> I want to break it up into four separate web pages with a NEXT button on
the
> first 3 pages and a complete on the last page. I'd like for the NEXT
button
> on the first page to create the record and have the remaining three pages
just
> update that record but I can't seem to get this to happen for me and I
know I'm
> just doing something wrong. The key for the table is an autogen number
but I
> haven't figured out how to grab the key after the record has been inserted
and
> pass it to the next page so that page can do an update. We use ASP (not
..NET)
>
> Please help me out! Any information/suggestions are appreciated!
> Michelle Jones 
> _________________
> Happy coding!
> mljonzs
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>
|
|
|
 |
Michelle
|
| Posted: 06/14/2006, 6:30 AM |
|
DonB --
Thank you, thank you, thank you and thank you again! 
I have been trying for months (literally) to get someone to help me with this! I will give your suggestions a try and let you know how things turn out!
Thank you yet again!
Michelle
|
|
|
 |
|