Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

on Insert, redirects and skips a page

Status
Not open for further replies.

OnAFan

Technical User
Mar 13, 2002
120
US
Hello everyone, I have a sequence of pages that carries info from one page to the next using session variables. Each is updated on submit with no problem. When I submit page 4 of 6, it skips page 5 and goes right to page 6. Any suggestions?
Each time I test the page sequence, a blank record is inserted into the table from the page 5 insert. Thanks in advance for your help. Below is the code for the page 5 update statement...
_____________________________________________________

<%
// *** Edit Operations: declare variables

// set the form action variable
var MM_editAction = Request.ServerVariables("SCRIPT_NAME");
if (Request.QueryString) {
MM_editAction += "?" + Server.HTMLEncode(Request.QueryString);
}

// boolean to abort record edit
var MM_abortEdit = false;

// query string to execute
var MM_editQuery = "";
%>
<%
// *** Insert Record: set variables

if (String(Request("MM_insert")) == "form1") {

var MM_editConnection = MM_conMIC3_STRING;
var MM_editTable = "dbo.tb_MIC_BGrnd_Srvy";
var MM_editRedirectUrl = "thanks.asp";
var MM_fieldsStr = "hfJobID2|value|hfUsername2|value|fld_Date|value|fld_YOB|value|fld_hearOther|value|fld_Hear1|value|fld_Hear2|value|fld_Hear3|value|fld_RaceOther|value|fld_Race|value|fld_Sex|value|fld_Ethnicity|value|fld_AUseDate|value|fld_AUseOccSup|value|fld_AUseOccSeries|value|fld_AUseAgeCode|value|fld_AUseLocation|value";
var MM_columnsStr = "fld_JobID|',none,''|fld_UserName|',none,''|fld_Date|',none,''|fld_YOB|',none,''|fld_HearOther|',none,''|fld_Hear1|',none,''|fld_Hear2|',none,''|fld_Hear3|',none,''|fld_RaceOther|',none,''|fld_Race|',none,''|fld_Sex|',none,''|fld_Ethnicity|',none,''|fld_Agency1|',none,''|fld_Agency2|',none,''|fld_Agency3|',none,''|fld_Agency4|',none,''|fld_Agency5|',none,''";

// create the MM_fields and MM_columns arrays
var MM_fields = MM_fieldsStr.split("|");
var MM_columns = MM_columnsStr.split("|");

// set the form values
for (var i=0; i+1 < MM_fields.length; i+=2) {
MM_fields[i+1] = String(Request.Form(MM_fields));
}

// append the query string to the redirect URL
if (MM_editRedirectUrl && Request.QueryString && Request.QueryString.Count > 0) {
MM_editRedirectUrl += ((MM_editRedirectUrl.indexOf('?') == -1)?"?":"&") + Request.QueryString;
}
}
%>
<%
// *** Insert Record: construct a sql insert statement and execute it

if (String(Request("MM_insert")) != "undefined") {

// create the sql insert statement
var MM_tableValues = "", MM_dbValues = "";
for (var i=0; i+1 < MM_fields.length; i+=2) {
var formVal = MM_fields[i+1];
var MM_typesArray = MM_columns[i+1].split(",");
var delim = (MM_typesArray[0] != "none") ? MM_typesArray[0] : "";
var altVal = (MM_typesArray[1] != "none") ? MM_typesArray[1] : "";
var emptyVal = (MM_typesArray[2] != "none") ? MM_typesArray[2] : "";
if (formVal == "" || formVal == "undefined") {
formVal = emptyVal;
} else {
if (altVal != "") {
formVal = altVal;
} else if (delim == "'") { // escape quotes
formVal = "'" + formVal.replace(/'/g,"''") + "'";
} else {
formVal = delim + formVal + delim;
}
}
MM_tableValues += ((i != 0) ? "," : "") + MM_columns;
MM_dbValues += ((i != 0) ? "," : "") + formVal;
}
MM_editQuery = "insert into " + MM_editTable + " (" + MM_tableValues + ") values (" + MM_dbValues + ")";

if (!MM_abortEdit) {
// execute the insert
var MM_editCmd = Server.CreateObject('ADODB.Command');
MM_editCmd.ActiveConnection = MM_editConnection;
MM_editCmd.CommandText = MM_editQuery;
MM_editCmd.Execute();
MM_editCmd.ActiveConnection.Close();

if (MM_editRedirectUrl) {
Response.Redirect(MM_editRedirectUrl);
}
}

}
%>
 
hi Terry!
"Hello everyone, I have a sequence of pages that carries info from one page to the next using session variables. "

- first dont use many sessions if u can help it; use 'URLparpameters' and 'Request Your Querrystrings'


"Each is updated on submit with no problem"
If we are talking UPDATE of the record creted by page1 then Insert command is compleatly out of place


In general:
blank record=
condition to Insert or NOT to inset is not right
or
the variables are not passed
----------------

Multi page forms:
Apporach 1
create a record at 1st page and then run Updates on each next page ( obivosly many trips to server and many SQL execitions...not the best way but sometimes the only way)

Approach 2
collect & pass all of your form entries through hidden fields and then use Last page to sumbit all the informtion( limiting to how much info can be submited at ones)


You have to find a "happy middle"...obvisoly if the page1 form allows for "memo entry" I would suggest u split your trips to the server....perhaps collect your data from 3 pages and do Insert and then on the final page do an Update


for your sample I would start with the "problem point" whihc as u say is at:
_____________________
// *** Insert Record: construct a sql insert statement and execute it
if (String(Request("MM_insert")) != "undefined")
_____________________
reads:
"if my string is NOT equal to word "undefined"

...well it will ALLWAYS be true...so your records are being acreated...
how about
if (String(Request("MM_insert")) != "")
_________________
"IF my string is NOT EMPTY (user has entred something) THEN
INSERT record ....
ELSE
"stop,send message,redirect....etc."
ENDIF


All the best!


:--------------------------------------------------------------------------:
fugitive.gif

ok,ok...I did shoot the deputy but he told me he was the sheriff!
:--------------------------------------------------------------------------:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top