 |
| Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

January 17th, 2006, 03:19 AM
|
|
Authorized User
|
|
Join Date: Jan 2006
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Dynamic Insert without Submit button key value
Hello-
I have the following:
Code:
For Each Key in Request.Form
Fields = Fields & Key & ","
Values = Values & "'" & Request.Form(Key) & "',"
Next
' knock off the final comma
Fields = Left(Fields, Len(Fields)-1)
Values = Left(Values, Len(Values)-1)
SQL = "INSERT yourtable (" & Fields & ") VALUES (" & Values & ")"
However this inserts the data with the submit button and value. How can I extract that out prior to sending to the insert command?
|
|

January 17th, 2006, 06:27 AM
|
|
Friend of Wrox
|
|
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
|
|
You could just use an if statement...
Code:
If Key <> "mySubmitButtonName" Then
Fields = Fields & Key & ","
Values = Values & "'" & Request.Form(Key) & "',"
End If
HTH,
Chris
|
|

January 17th, 2006, 12:53 PM
|
|
Authorized User
|
|
Join Date: Jan 2006
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
That does not seem to work. I get an expected statement warning each time?
|
|

January 17th, 2006, 01:07 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Works fine for me with this code:
Code:
Dim Fields, Values
For Each Key in Request.Form
If Key <> "submit" Then
Fields = Fields & Key & ","
Values = Values & "'" & Request.Form(Key) & "',"
End If
Next
' knock off the final comma
Fields = Left(Fields, Len(Fields)-1)
Values = Left(Values, Len(Values)-1)
SQL = "INSERT yourtable (" & Fields & ") VALUES (" & Values & ")"
Response.Write SQL
What output do you get from the Response.Write SQL line?
Which line do you get the error on?
|
|

January 17th, 2006, 01:11 PM
|
|
Authorized User
|
|
Join Date: Jan 2006
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Ok, got it working. However I have more than 1 thing i need to check for. Is there a way to do that if statement twice? I have Submit and cname that i need to check for. When I try an if or statement it ignores it?
|
|

January 17th, 2006, 01:23 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Code:
If Key <> "Submit" And Key <> "cname" Then
Should work fine.
HTH,
Chris
|
|

January 17th, 2006, 01:26 PM
|
|
Authorized User
|
|
Join Date: Jan 2006
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Ok, I did that and it still includes the cname? If I do 1 or the other such as submit or cname it keeps those out? Any ideas? Thankas for your help!
Dim Fields, Values
For Each Key in Request.Form
If Request.Form(Key) <> "Submit" and Request.Form(Key) <> "cname" Then
Fields = Fields & Key & ","
Values = Values & "'" & Request.Form(Key) & "',"
end if
Next
|
|

January 17th, 2006, 01:31 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Can you post the html of your form please?
Cheers,
Chris
|
|

January 17th, 2006, 01:34 PM
|
|
Authorized User
|
|
Join Date: Jan 2006
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
<%
Error = Request.Querystring("Error")
cnumber=session("cnumber")
ClientID = session("ClientID")
CName = session("CName")
ThisYear = Year(Date())
Today = Year(Date)& "-" & Month(Date) & "-" & Day(Date)
LastYear = ThisYear - 1
If Request.form <> "" then
'Compile form fields
Dim Fields, Values
For Each Key in Request.Form()
If Request.Form(Key) <> "Submit" and Request.Form(Key) <> "cname" Then
Fields = Fields & Key & ","
Values = Values & "'" & Request.Form(Key) & "',"
end if
Next
' knock off the final comma
Fields = Left(Fields, Len(Fields)-1)
Values = Left(Values, Len(Values)-1)
SQL = "INSERT yourtable (" & Fields & ") VALUES (" & Values & ")"
Response.Write(SQL)
end if
%>
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Supplemental Services Information</title>
<style>
v\:* { behavior: url(#default#VML) }
o\:* { behavior: url(#default#VML) }
.shape { behavior: url(#default#VML) }
</style>
</head>
<body>
<div align="left">
<table border="0" cellpadding="0" cellspacing="0" width="640" id="table1">
<tr>
<td><span style='mso-ignore:vglayout;position:
absolute;z-index:-1;left:93px;top:-349px;width:61px;height:56px'><img width=61
height=56 src="../newtest/genliability_files/image002.jpg" v:shapes="_x0000_s1025"></span></td>
</tr>
</table>
</div>
<div align="left">
<table border="1" cellpadding="0" cellspacing="0" width="693" id="table2" bordercolor="#907C64">
<tr>
<td valign="top">
<div align="center">
<table border="0" cellpadding="0" cellspacing="0" id="table3" width="503">
<tr>
<td>
<img border="0" src="../images/ecinsure.png" width="60" height="56"><span style="font-size: 14.5pt; font-family: Century Schoolbook; mso-bidi-font-family: Century Schoolbook">
</span></td>
<td valign="top">
<p align="center">
<span style="font-size: 14.5pt; font-family: Century Schoolbook; mso-bidi-font-family: Century Schoolbook">
Supplemental Services Information<o:p></o:p></span></td>
</tr>
</table>
</div>
<form method="POST" action="?" name="FrontPage_Form1" onsubmit="return FrontPage_Form1_Validator(this)" language="JavaScript">
<input type="hidden" name="Year_Completed" value="<%=ThisYear%>">
<input type="hidden" name="Date_Completed" value="<%=Today%>">
<p class="MsoNormal" style="line-height: 9.5pt; mso-line-height-rule: exactly; mso-pagination: none; tab-stops: 112.0pt; mso-layout-grid-align: none; text-autospace: none; margin-left: 0in; margin-right: -1.0pt; margin-top: .1pt; margin-bottom: .0001pt">
<span style="font-family: Eras Light ITC">EC Co#<span style="mso-tab-count: 1">: </span></span><span style="font-size: 9.5pt; font-family: Arial"><input name="cnumber" size="20" style="background-color: #C0C0C0" value="<%=cnumber%>" readonly></span><span style="font-family: Eras Light ITC">
EC Co. Name:</span><span style="font-size: 9.5pt; font-family: Arial"><o:p><input name="cname" size="37" style="background-color: #C0C0C0" value="<%=cname%>" readonly></o:p></span></p>
<ol>
<li>
<p class="MsoNormal" style="line-height: 12.0pt; mso-line-height-rule: exactly; mso-pagination: none; mso-layout-grid-align: none; text-autospace: none; margin-right: -1.0pt">
<span style="font-family: Eras Light ITC">
<b>Who are
your customers?</b><i> </i>
Please indicate if any of the
following are a part of our business.</span></p></li>
</ol>
<div align="center">
<div align="left">
<table border="0" id="table7" width="663" cellspacing="1">
<tr>
<td width="36" align="center" bgcolor="#C0C0C0" valign="top">
<b>YES</b></td>
<td align="center" width="29" bgcolor="#C0C0C0" valign="top">
<input type="radio" name="office_Buildings" value="Y"></td>
<td align="center" width="36" bgcolor="#C0C0C0" valign="top">
<b>NO</b></td>
<td align="center" width="26" bgcolor="#C0C0C0" valign="top">
<input type="radio" name="office_Buildings" value="N"></td>
<td width="193">
office
buildings</td>
<td width="32" align="center" bgcolor="#C0C0C0" valign="top">
<b>YES</b></td>
<td align="center" width="22" bgcolor="#C0C0C0" valign="top">
<input type="radio" name="Nursing_Homes" value="Y"></td>
<td align="center" width="29" bgcolor="#C0C0C0" valign="top">
<b>NO</b></td>
<td width="21" align="center" bgcolor="#C0C0C0" valign="top">
<input type="radio" name="Nursing_Homes" value="N"></td>
<td> nursing
homes</td>
</tr>
<tr>
<td width="36" align="center" bgcolor="#C0C0C0" valign="top">
<b>YES</b></td>
<td align="center" width="29" bgcolor="#C0C0C0" valign="top">
<input type="radio" name="Hospitals" value="Y"></td>
<td align="center" width="36" bgcolor="#C0C0C0" valign="top">
<b>NO</b></td>
<td align="center" width="26" bgcolor="#C0C0C0" valign="top">
<input type="radio" name="Hospitals" value="N"></td>
<td width="193">
hospitals</td>
<td width="32" align="center" bgcolor="#C0C0C0" valign="top">
<b>YES</b></td>
<td align="center" width="22" bgcolor="#C0C0C0" valign="top">
<input type="radio" name="Supermarkets" value="Y"></td>
<td align="center" width="29" bgcolor="#C0C0C0" valign="top">
<b>NO</b></td>
<td width="21" align="center" bgcolor="#C0C0C0" valign="top">
<input type="radio" name="Supermarkets" value="N"></td>
<td> supermarkets</td>
</tr>
<tr>
<td width="36" align="center" bgcolor="#C0C0C0" valign="top">
<b>YES</b></td>
<td align="center" width="29" bgcolor="#C0C0C0" valign="top">
<input type="radio" name="Mfg_Plants" value="Y"></td>
<td align="center" width="36" bgcolor="#C0C0C0" valign="top">
<b>NO</b></td>
<td align="center" width="26" bgcolor="#C0C0C0" valign="top">
<input type="radio" name="Mfg_Plants" value="N"></td>
<td width="193">
manufacturing
plants</td>
<td width="32" align="center" bgcolor="#C0C0C0" valign="top">
<b>YES</b></td>
<td align="center" width="22" bgcolor="#C0C0C0" valign="top">
<input type="radio" name="Airports" value="Y"></td>
<td align="center" width="29" bgcolor="#C0C0C0" valign="top">
<b>NO</b></td>
<td width="21" align="center" bgcolor="#C0C0C0" valign="top">
<input type="radio" name="Airports" value="N"></td>
<td> airports</td>
</tr>
<tr>
<td width="36" align="center" bgcolor="#C0C0C0" valign="top">
<b>YES</b></td>
<td align="center" width="29" bgcolor="#C0C0C0" valign="top">
<input type="radio" name="Retail" value="Y"></td>
<td align="center" width="36" bgcolor="#C0C0C0" valign="top">
<b>NO</b></td>
<td align="center" width="26" bgcolor="#C0C0C0" valign="top">
<input type="radio" name="Retail" value="N"></td>
<td width="193">
retail
stores</td>
<td width="32" align="center" bgcolor="#C0C0C0" valign="top">
<b>YES</b></td>
<td align="center" width="22" bgcolor="#C0C0C0" valign="top">
<input type="radio" name="Hotels" value="Y"></td>
<td align="center" width="29" bgcolor="#C0C0C0" valign="top">
<b>NO</b></td>
<td width="21" align="center" bgcolor="#C0C0C0" valign="top">
<input type="radio" name="Hotels" value="N"></td>
<td> hotels</td>
</tr>
<tr>
<td width="36" align="center" bgcolor="#C0C0C0" valign="top">
<b>YES</b></td>
<td align="center" width="29" bgcolor="#C0C0C0" valign="top">
<input type="radio" name="Schools" value="Y"></td>
<td align="center" width="36" bgcolor="#C0C0C0" valign="top">
<b>NO</b></td>
<td align="center" width="26" bgcolor="#C0C0C0" valign="top">
<input type="radio" name="Schools" value="N"></td>
<td width="193">
schools</td>
<td width="32" align="center" bgcolor="#C0C0C0" valign="top">
<b>YES</b></td>
<td align="center" width="22" bgcolor="#C0C0C0" valign="top">
<input type="radio" name="Shopping_Malls" value="Y"></td>
<td align="center" width="29" bgcolor="#C0C0C0" valign="top">
<b>NO</b></td>
<td width="21" align="center" bgcolor="#C0C0C0" valign="top">
<input type="radio" name="Shopping_Malls" value="N"></td>
<td> shopping
malls</td>
</tr>
<tr>
<td width="36" align="center" bgcolor="#C0C0C0" valign="top">
<b>YES</b></td>
<td align="center" width="29" bgcolor="#C0C0C0" valign="top">
<input type="radio" name="Govt_Bldgs" value="Y"></td>
<td align="center" width="36" bgcolor="#C0C0C0" valign="top">
<b>NO</b></td>
<td align="center" width="26" bgcolor="#C0C0C0" valign="top">
<input type="radio" name="Govt_Bldgs" value="N"></td>
<td width="193">
Govt.
bldgs./contracts</td>
<td width="32" align="center" bgcolor="#C0C0C0" valign="top">
<b>YES</b></td>
<td align="center" width="22" bgcolor="#C0C0C0" valign="top">
<input type="radio" name="Other_Cust" value="Y"></td>
<td align="center" width="29" bgcolor="#C0C0C0" valign="top">
<b>NO</b></td>
<td width="21" align="center" bgcolor="#C0C0C0" valign="top">
<input type="radio" name="Other_Cust" value="N"></td>
<td> other (<b>Must
Describe below</b>)</td>
</tr>
</table>
</div>
<p class="MsoNormal" style="line-height: 9.5pt; text-autospace: none; margin-left: 0in; margin-right: -1.0pt; margin-top: .1pt; margin-bottom: .0001pt" align="left">
<b>
<span style="font-size: 9.5pt; font-family: Eras Light ITC"><br>
</span></b>
<span style="font-size: 9.5pt; font-family: Century Schoolbook">
<b>
Comments: <br>
<textarea rows="3" name="Other_Cust_Comments" cols="77" style="background-color: #C0C0C0"></textarea></b><i><br>
</i></span></p>
<ol>
<li value="2">
<p class="MsoNormal" style="line-height: 9.5pt; text-autospace: none; margin-left: 0in; margin-right: -1.0pt; margin-top: .1pt; margin-bottom: .0001pt" align="left">
<span style="font-size: 9.5pt"><b>
What types of services are provided?</b> </span>
Please indicate
if any of the following are part of the services you
provide?</p></li>
</ol>
<div align="left">
<div align="left">
<table border="0" id="table8" width="665" cellspacing="1">
<tr>
<td width="36" align="center" bgcolor="#C0C0C0">
<b>YES</b></td>
<td align="center" width="28" bgcolor="#C0C0C0">
<input type="radio" name="Gen_Cleaning" value="Y"></td>
<td align="center" width="37" bgcolor="#C0C0C0">
<b>NO</b></td>
<td align="center" width="26" bgcolor="#C0C0C0">
<input type="radio" name="Gen_Cleaning" value="N"></td>
<td width="194">
general cleaning
(vac, dust,
trash)</td>
<td width="31" align="center" bgcolor="#C0C0C0">
<b>YES</b></td>
<td align="center" width="22" bgcolor="#C0C0C0">
<input type="radio" name="Ind_Clean" value="Y"></td>
<td align="center" width="29" bgcolor="#C0C0C0">
<b>NO</b></td>
<td width="20" align="center" bgcolor="#C0C0C0">
<input type="radio" name="Ind_Clean" value="N"></td>
<td> industrial
cleaning</td>
</tr>
<tr>
<td width="36" align="center" bgcolor="#C0C0C0">
<b>YES</b></td>
<td align="center" width="28" bgcolor="#C0C0C0">
<input type="radio" name="bldg_renovation" value="Y"></td>
<td align="center" width="37" bgcolor="#C0C0C0">
<b>NO</b></td>
<td align="center" width="26" bgcolor="#C0C0C0">
<input type="radio" name="bldg_renovation" value="N"></td>
<td width="194">
bldg
construction/renovation</td>
<td width="31" align="center" bgcolor="#C0C0C0">
<b>YES</b></td>
<td align="center" width="22" bgcolor="#C0C0C0">
<input type="radio" name="Degreasing" value="Y"></td>
<td align="center" width="29" bgcolor="#C0C0C0">
<b>NO</b></td>
&nb
|
|

January 17th, 2006, 01:49 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Your fields are named "cname" and "Submit", and I guess the "cname" field does not contain the value "cname" so you need to check these values against Key and not Request.Form(Key), e.g.
Code:
If Key <> "Submit" And Key <> "cname" Then
not
Code:
If Request.Form(Key) <> "Submit" and Request.Form(Key) <> "cname" Then
HTH,
Chris
|
|
 |