473,491 Members | 2,133 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Code Doesn't Listen...Avoids Sub & Inserts Data Twice???

I have the following code that populates 3 independent drop-down boxes with
data from arrays. From there the user can select a value from a drop-down
list, or input data into a text box. The user then submits this to be
inserted into the database. Currently I've only programmed to have the first
input box/drop-down valid. The problem I am having is that, even though I've
inserted my SQL into a sub procedure, the code is still run prior to me
making a call to the sub, therefore allowing the data to be inserted twice
into the database. I know the obvious thing would be to add "no duplicates"
on the db table, but I really would like to know who/why the Insert gets
executed twice. I apologize for the amount of code. Thanks!
<html>
<head>
<script language="JavaScript">
alert("hello - head1")
</script>

<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<title>EITA SA, Env, Plat Update</title>

<script language="JavaScript">
alert("hello - head2")
</script>
</head>

<body topmargin=0 leftmargin=0>

<script language="JavaScript">
alert("hello - body1")
</script>
<script language="JavaScript">
alert("hello - body2")
</script>

<%
dim compMode
dim objConn, objRS, duplicate
dim test
dim executeDisplay, executeUpdate
dim sSQL, SAarr, Env_arr, PF_arr
dim i, nRows, bRows
duplicate = false
dim SAaarr(100,100)

'''''''''''''''''''''''''''''''''SA''''''''''''''' ''''''''''''''''''''''
'-------------------------------------------'
'Start Main
'-------------------------------------------'
strMode = Request.QueryString("compMode")

if not isEmpty(Request.QueryString("compMode")) then
strMode = Request.QueryString("compMode")
else
strMode = "new"
end if
%>
<script language="VBScript">
msgTxt = "strMode: " & "<%=strMode%>"
msgbox msgTxt
</script>
<%

select case strMode
case "new"
getFormData()
displayForm()
case "save"
updateTables()
%>
<script language="VBScript">
msgTxt = "Tables updated. Stopping execution."
msgbox msgTxt
</script>
<%
displayForm()
case else
%>
<script language="VBScript">
msgTxt = "strMode NOT set: *" & "<%=strMode%>" & "*"
msgbox msgTxt
</script>
<%
end select
'---------------------------------------------'
'End Main
'---------------------------------------------'

sub getFormData()
sSQL = "Select service_area_id, service_area_title From d_service_area
order by d_service_area.service_area_title;"
'msg="Error: "
msg = "drb-a"
Call ExecSQL(sSQL, msg, false)
'Set objRS1 = dbConn.Execute(sSQL1)
SAarr = objRS.GetRows
nColumn = ubound(SAarr) ' lenght of the column
nRows = ubound(SAarr, 2)

objRS.Close
Set objRS = Nothing

'insert space in the first element
For i = 0 to nRows
SAaarr(0,i+1) = SAarr(0,i)
next
For i = 0 to nRows
SAaarr(1,i+1) = SAarr(1,i)
next
''''''''''''''''''''''''''''''''

''''''''''''''''''''''''''''''En'''''''''''''''''' ''''''''''''''''''''''''
sSQL = "Select environment_id, environment_key From d_environment order by
d_environment.environment_key;"
'msg="Error: "
msg = "drb-b"
Call ExecSQL(sSQL, msg, false)

Env_arr = objRS.GetRows

bColumn = ubound(Env_arr)
bRows = ubound(Env_arr, 2)

objRS.Close
Set objRS = Nothing

'''''''''''''''''''''''''''''PL''''''''''''''''''' ''''''''''''''''''''''''
sSQL = "Select platform_function_id, platform_function From
d_platform_function order by d_platform_function.platform_function;"
'msg="Error: "
msg = "drb-c"
Call ExecSQL(sSQL, msg, false)

PF_arr = objRS.GetRows

cColumn = ubound(PF_arr)
cRows = ubound(PF_arr, 2)

objRS.Close
Set objRS = Nothing

'Response.Write ("strMode = " & strMode)

end sub
sub updateTables()

'objConn.close

dim msgTxt

'sSQL = "INSERT INTO d_service_area(service_area_title) VALUES ('" &
Request.Form("SA_InputBox") & "');"
%>
<script language="VBScript">
msgTxt = "Getting ready to execute INSERT"
msgbox msgTxt
</script>
<%
dim serviceAreaTitle
serviceAreaTitle = Request.Form("SA_InputBox")

sSQL = ""
sSQL = "INSERT INTO d_service_area ( service_area, service_area_title,
sa_logical_link, sa_physical_link ) " & _
"VALUES ('drbSvcArea', '" & serviceAreaTitle & "', 'noLogLink',
'noPhysLink');"

%>
<script language="VBScript">
msgTxt = "sSQL= " & "<%=sSQL%>"
msgbox msgTxt
</script>
<script language="VBScript">
msgTxt = "Service Area input value: " & "<%=serviceAreaTitle%>"
msgTxt = msgTxt & vbCrLf & "sSQL= " & "<%=sSQL%>"
msgbox msgTxt
</script>
<%
'????????????????????????????????????????????????? ?????????????????????????????????????????????????
' drbTest
'????????????????????????????????????????????????? ?????????????????????????????????????????????????
'dim rsSA, dbConn
On Error Resume Next
%>
<script language="VBScript">
msgbox "before ExecSQL"
</script>
<%
msg = "drb-d"
Call ExecSQL(sSQL,msg,true)
%>
<script language="VBScript">
msgTxt = "sSQL= " & "<%=sSQL%>"
msgTxt = msgTxt & "after ExecSQL"
msgbox msgTxt
</script>
<%
'????????????????????????????????????????????????? ?????????????????????????????????????????????????
' drbTest
'????????????????????????????????????????????????? ?????????????????????????????????????????????????
'set rsSA = dbConn.Execute(sSQL)

if Err.number <> 0 then
Response.write
"************************************************* ****************<br>"
Response.write " APPLICATION ERROR: " & Err.number & "<br>"
Response.write " Error description: [" & err.description & "]<br>"
Response.write
"************************************************* ****************<br>"
else
Response.write " INSERT Successful. Error number: " & Err.number
end If

'Response.Write "ENDING AFTER SQL EXECUTION"
'reponse.end

'response.write "strSA:" & strSA
'Response.Write "ran SQL"
if duplicate then
%>
<script language="javascript">
temp = "Duplicate Record1. ";
temp = temp + "This item already exists. ";
temp = temp + "Please review your values. ";
alert(temp);
history.go(-1)
</script>
<%
objConn.close
set objRS = nothing
end if
end sub

dim ErrsList, errLoop
'------------------------------------------------------------------
'Pre: datastore.asp need to be included to the same file as this one
' : sql statement for sql variable
' : error message for msg variable
' : True/False value for CloseInd variable
'Pro: sql statement executed or Erro msg pop up
'-------------------------------------------------------------------
Function ExecSQL(sql,msg,closeInd)
' The ind determines whether to close the connection or not.
set objConn = nothing
set objConn = server.createobject("ADODB.Connection")
objConn.Open strConnect
'Response.Write("sSQL = " & sSQL)
On Error Resume Next
set objRS = objConn.Execute(sql)

'Response.Write "Error" & Err.number & "<br>"
'Response.Write "Error" & Err.description & "<br>"
'Response.Write "Error" & Err.source & "<br>"
'Response.Write "Error" & Err.line & "<br>"

%>
<script language="VBscript">
'msgbox ("from execSQL: msg = " & "<%=msg%>" & vbCrLf & "SQL = " &
"<%=sql%>")
</script>
<%

'Response.Write "VB:" & vbobjecterror & "<br>"
if Err.number <> 0 then
if (err.number - vbobjecterror) = 3604 then
duplicate = true
else
%>
<script language="javascript">
temp = "<%=msg%>";
temp = temp + "Database Error (" + <%=err.number%> + "): " +
"<%=CSTR(err.description)%>" + ".";
temp = temp + " " + "<%=sSQL%>";
alert(temp);
// history.go(-1)
</script>
<%
end if
end if
if closeInd = true then
objConn.close
set objRS = nothing
end if

End Function

%>

<%
sub displayForm()
%>
<center><span class="hdrAr12">EITA SA, Env, Plat Update</span></center><br>
<Form action="SAEnvPlatUpd.asp?compMode=save" Method="post" name="Form_1">
<table name="tbl1" id="tbl1" border=0 align="center" width="98%">
<tr>
<!--------------Service Area--------------->
<th>
<font COLOR='navy'><b>Service Area:</b></font>
<BR>
<input type="text" name="SA_InputBox" Size="35" value="">
<BR>
<select name="SA_DropDown" onChange="displaySABox()">
<%for i = 0 to nRows %>
<option value="<%=(SAaarr(0,i))%>"><%=(SAaarr(1,i))%></option>
<%next%>
</select>
<input type="hidden" value="" name="SA_hidden">
</th>
<!--------------Environment----------------->
<th>
<font COLOR='navy'><b>Environment:</b></font>
<BR>
<input type="text" name="En_InputBox" Size="32.5" value="">
<BR>
<select name="En_DropDown" onClick="displayEnBox()">
<%for i = 0 to bRows%>
<option value="<%=(Env_arr(0,i))%>"><%=(Env_arr(1,i))%></option>
<%next%>
</select>
<input type="hidden" value="" name="En_hidden">
</th>
<!--------------Platform--------------------->
<th>
<font COLOR='navy'><b>Platform Area:</b></font>
<BR>
<input Name="PF_InputBox" Size="39" value="">
<BR>
<select name="PF_DropDown" onChange="displayPFBox()">
<%for i = 0 to cRows %>
<option value="<%=(PF_arr(0,i))%>"><%=(PF_arr(1,i))%> </option>
<%next%>
</select>
<input type="hidden" value="" name="PF_hidden">
</th>
</tr>
<tr>
<th>
</th>
<th>
<br>

<!--<center> <INPUT type="submit" name="SaveButton" Value="save/exit"
onClick="save()" >-->
<center>

<!--------------ZONK--------------------->
<INPUT type="submit" name="SaveButton" Value="save/exit"
onClick="javascript:Form_1.submit()" >
<INPUT type="button" name="btnCancel" value="Return"
onclick="exitPage()" accesskey="r"></input>

<!--<INPUT type="submit" onClick="Message_pop()" name="SaveButton"
Value="save/exit" >-->
</center>
</th>
</tr>
<!-- <input type="hidden" name="mode" value="GO"></input>
-->
</table>
</Form>

<%
end sub
%>

<script language="JavaScript">
function displaySABox()
{
var sel = document.Form_1.SA_DropDown;
var val = sel.options[sel.selectedIndex].value;
var txt = sel.options[sel.selectedIndex].text;
document.Form_1.SA_hidden.value = val;
document.Form_1.SA_InputBox.value = txt;
}

function displayEnBox()
{
var sel = document.Form_1.En_DropDown;
var val = sel.options[sel.selectedIndex].value;
var txt = sel.options[sel.selectedIndex].text;
document.Form_1.En_hidden.value = val;
document.Form_1.En_InputBox.value = txt;
}

function displayPFBox()
{
var sel = document.Form_1.PF_DropDown;
var val = sel.options[sel.selectedIndex].value;
var txt = sel.options[sel.selectedIndex].text;
document.Form_1.PF_hidden.value = val;
document.Form_1.PF_InputBox.value = txt;
}
function exitPage()
{
document.Form_1.action = "a_eita1.asp";
document.Form_1.submit();
}
</script>
</body>
</html>











Jul 22 '05 #1
1 2071
SABmore [S], on Wednesday, June 29, 2005 at 11:29 (-0700) wrote:

S> I have the following code that populates 3 independent drop-down boxes with
S> data from arrays. From there the user can select a value from a drop-down
S> list, or input data into a text box. The user then submits this to be
S> inserted into the database. Currently I've only programmed to have the first
S> input box/drop-down valid. The problem I am having is that, even though I've

Common problem; you have to insert those values at second page, and at end
response.redirect to source page. More at
http://www.theserverside.com/article...irectAfterPost

it is interesting reading.

--

How do you protect mail on web? I use http://www.2pu.net

[Rubuncles - The bumps on uncooked chicken.]

Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
2567
by: Akbar | last post by:
Hey there, Big-time curiosity issue here... Here's the test code (it's not that long)... it's to display a large number of image links with captions, ideally pulled in from an external file...
1
3767
by: Zaidan | last post by:
I am running Excel2000 under WIN98 2nd edition, and I am writing a VBA code (I will consider using javascript if I have to) that does the following, at the user command: 1- Start MS Explorer and...
33
3910
by: n00m | last post by:
import socket, thread host, port = '192.168.0.3', 1434 s1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s2.connect((host, 1433))...
10
1886
by: saraca means ashoka tree | last post by:
The following code is the heart of a program that I wrote to extract html tags from a webpage. How efficient is my code ?. Is there still possible way to optimize the code. Am I using everything as...
29
3641
by: John Rivers | last post by:
Hello, What good reason there is for not allowing methods in ASPX pages I can't imagine, but here is how to get around that limitation: (START) <body MS_POSITIONING="FlowLayout"> <form...
23
8162
by: Steven T. Hatton | last post by:
This is one of the first obstacles I encountered when getting started with C++. I found that everybody had their own idea of what a string is. There was std::string, QString, xercesc::XMLString,...
2
1590
by: Bob | last post by:
Hi, (already posted but unsolved) this code inserts twice the same record. I thin it is due to the "Selet Scope_Identity" in the sqlcommand. If i remove the Select part, the inserts occurs only...
14
1917
by: Alexander Stoyakin | last post by:
Hello! Please advise on the following issue. I have a function which returns 1 or 0 in multiple branches, and it must perform the same code before each return, like this: int fun() { if (some...
4
2841
by: David C | last post by:
I spent the last four hours trying to figure out why Page_Load would execute twice. Even stranger was that everything within if (! IsPostBack){....} executed twice as well. There is no rhyme or...
0
7115
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7154
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7360
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5451
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4578
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3086
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3076
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1392
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
633
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.