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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Problems

Status
Not open for further replies.

Gwen21

Programmer
Apr 5, 2002
16
US
The problem I am running into is that the form is submitting twice to my database. It creates one good record and one blank record
The problem seems to be that in the form tag I have not stated an action which by default sets it to submit to itself.

This is the select statement that starts the form and gives it a unique ID and creates the record:
<%
Set objRS = Server.CreateObject(&quot;ADODB.Recordset&quot;) 'Adds one to the highest PNumber
strSQL = &quot;SELECT MAX(Pnumber) AS PNumber FROM Pindex&quot;

strSQL = &quot;INSERT INTO PIndex (date_entered) VALUES ('&quot; & Date() & &quot;');&quot;
strSQL = strSQL & &quot;SELECT @@IDENTITY AS thisID;&quot;
Set objRS = objConn.Execute(strSQL)
Set objRS = objRS.NextRecordSet()
intPNo = objRS(&quot;thisID&quot;)
%>

Then is all the form stuff

Then I have an IF..THen statement that checks what is being sent to the database and updates the record that was created when the form was opened in the database and redirects the user to the next page

If NOT Request(&quot;ActionButton&quot;) =&quot;&quot; Then
If strDuration = &quot;Permanent&quot; and strActualDate =&quot;&quot; Then
strEnterData = &quot;UPDATE PIndex SET Type_of_Process_Change = '&quot; & strTypeChange & &quot;', Requestor = '&quot; & strRequestor & &quot;', Location = '&quot; & strLocation & &quot;', &quot;&_
&quot;Part_Number='&quot; & strPartNo & &quot;', Project_ID='&quot; & strProjectNo & &quot;', Work_Center='&quot; & strWorkCenter & &quot;', Asset_Number='&quot; & strAsset & &quot;', &quot;&_
&quot;Work_Station='&quot; & strStationNo & &quot;', Operation_Number= '&quot; & strOPNo & &quot;', Current_Process_Condition='&quot; & strCurrent & &quot;', &quot;&_
&quot;Proposed_Process_Condition = '&quot; & strProposed & &quot;', Justification_for_Proposal= '&quot; & strJustification & &quot;', Action_Plan_for_Imp = '&quot; & strAction & &quot;', &quot;&_
&quot;Target_Date = '&quot; & strTargetDate & &quot;', MRB= '&quot; & strMRB & &quot;', Improvement='&quot; & strImprovement & &quot;', &quot;&_
&quot;Database_Updated= '&quot; & strMFGPro & &quot;', ECN_Number= '&quot; & strECN & &quot;', Customer_Complaint= '&quot; & strCustComplaint & &quot;', &quot;&_
&quot;Plant_Layout_Updated = '&quot; & strPlantLayout & &quot;', Duration = '&quot; & strDuration & &quot;', Estimated_Cost_Recovery =&quot; & strEstCost & &quot;, &quot;&_
&quot;Disposition_of_Request = '&quot; & strDisRequest & &quot;' WHERE PNumber = &quot;& Request.QueryString(&quot;PNo&quot;)


ElseIf strDuration =&quot;Short Term&quot; and NOT strActualDate =&quot;&quot; Then
strEnterData = &quot;UPDATE PIndex SET Type_of_Process_Change = '&quot; & strTypeChange & &quot;', Requestor = '&quot; & strRequestor & &quot;', Location = '&quot; & strLocation & &quot;', &quot;&_
&quot;Part_Number='&quot; & strPartNo & &quot;', Project_ID='&quot; & strProjectNo & &quot;', Work_Center='&quot; & strWorkCenter & &quot;', Asset_Number='&quot; & strAsset & &quot;', &quot;&_
&quot;Work_Station='&quot; & strStationNo & &quot;', Operation_Number= '&quot; & strOPNo & &quot;', Current_Process_Condition='&quot; & strCurrent & &quot;', &quot;&_
&quot;Proposed_Process_Condition = '&quot; & strProposed & &quot;', Justification_for_Proposal= '&quot; & strJustification & &quot;', Action_Plan_for_Imp = '&quot; & strAction & &quot;', &quot;&_
&quot;Target_Date = '&quot; & strTargetDate & &quot;', Actual_Date= '&quot; & strActualDate & &quot;', MRB= '&quot; & strMRB & &quot;', Improvement='&quot; & strImprovement & &quot;', &quot;&_
&quot;Database_Updated= '&quot; & strMFGPro & &quot;', ECN_Number= '&quot; & strECN & &quot;', Customer_Complaint= '&quot; & strCustComplaint & &quot;', &quot;&_
&quot;Plant_Layout_Updated = '&quot; & strPlantLayout & &quot;', Duration = '&quot; & strDuration & &quot;', Estimated_Cost_Recovery =&quot; & strEstCost & &quot;, &quot;&_
&quot;Disposition_of_Request = '&quot; & strDisRequest & &quot;', Start_Date = '&quot; & strStartDate & &quot;', End_Date = '&quot; & strEndDate & &quot;' WHERE PNumber = &quot;& Request.QueryString(&quot;PNo&quot;)
End IF

If Request(&quot;ActionButton&quot;) = &quot;&quot; Then
'Response.Write &quot;Please enter Plan of Action before hitting submit.&quot;
Else
objConn.Execute(strEnterData)
'Response.Write(strEnterData)
Response.Redirect &quot;Transition1.asp?intPNo=&quot; &server.urlEncode(request(&quot;PNo&quot;)) 'redirects to Transition page
End If
End If

%>

When I change the form tag to have an action to send to a different page the data doesn't go to the database.
I am new at this and really don't see where I am messing this up.

Can some one give me a clue as to what to change to get this to work.

Any help would be GREATLY appreciated .

Thanks
 
If you don't have a condition around your insert, then the insert code will run as soon as you load this page (inserting a blank record), then will run again when you submit your page (inserting a record with values, rather than just updating the record you have already created.)

Put some sort of condition around your insert. If you want to initially create a blank record then try something like this (assuming that ActionButton is on your form):

If Request(&quot;ActionButton&quot;)=&quot;&quot; then
... insert blank record
end if

If you only want to create the record after the the form has been submitted, then do the opposite:

if Request(&quot;ActionButton&quot;)<>&quot;&quot; then
... insert record
end if


I hope this helps you out. If I have misunderstood your problem, please post back.
 
Sarkman
Yes all of the abov code is on the same page.

JuanitaC
Thank you So much that seems to have fixed the problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top