Wrox Programmer Forums
|
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
 
Old January 17th, 2006, 03:19 AM
Authorized User
 
Join Date: Jan 2006
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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?

 
Old January 17th, 2006, 06:27 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

You could just use an if statement...
Code:
If Key <> "mySubmitButtonName" Then
    Fields = Fields & Key & ","
    Values = Values & "'" & Request.Form(Key) & "',"
End If
HTH,

Chris

 
Old January 17th, 2006, 12:53 PM
Authorized User
 
Join Date: Jan 2006
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That does not seem to work. I get an expected statement warning each time?

 
Old January 17th, 2006, 01:07 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

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?

 
Old January 17th, 2006, 01:11 PM
Authorized User
 
Join Date: Jan 2006
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?

 
Old January 17th, 2006, 01:23 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Code:
If Key <> "Submit" And Key <> "cname" Then
Should work fine.

HTH,

Chris

 
Old January 17th, 2006, 01:26 PM
Authorized User
 
Join Date: Jan 2006
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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


 
Old January 17th, 2006, 01:31 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Can you post the html of your form please?

Cheers,

Chris



 
Old January 17th, 2006, 01:34 PM
Authorized User
 
Join Date: Jan 2006
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default


<%
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">:&nbsp;</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">
                                &nbsp;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>&nbsp;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">
                                &nbsp;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>&nbsp;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">
                                &nbsp;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>&nbsp;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">
                                &nbsp;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>&nbsp;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">
                                &nbsp;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>&nbsp;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">
                                &nbsp;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>&nbsp;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>
&nbsp;</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">

                                    &nbsp;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>&nbsp;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">
                                    &nbsp;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
 
Old January 17th, 2006, 01:49 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

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






Similar Threads
Thread Thread Starter Forum Replies Last Post
Make a image button as default submit button toshi ASP.NET 1.0 and 1.1 Basics 1 June 1st, 2006 05:25 AM
Submit Button trusslady Infopath 2 January 6th, 2006 05:19 PM
submit-button grstad Javascript How-To 1 May 25th, 2005 08:33 AM
submit the form by hitting the enter key rajiv_software Classic ASP Basics 1 April 26th, 2005 07:19 AM
Submit Button Night_Zero Classic ASP Databases 1 August 17th, 2004 04:55 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.