Multiple html Forms & DB Inserts
Multiple html Forms & DB Inserts
am 20.12.2004 16:21:05 von Jim in Arizona
I've got more than one form on a single ASP page. The top combo box is
populated from an access database with job titles. The field below it, in
its own form, is a text field that one can put a new job title into, press
the submit button and add the new title to the access table which is
populating the combo box in the first form on the same ASP page.
Originally I wanted to run everything within the same asp page but it wasn't
working out for me. Instead I decided to have the second form on the asp
page to point to some code on another asp page. When this code was ran it
would then redirect back to the first asp.
Here's my error:
a.. Error Type:
Microsoft JET Database Engine (0x80004005)
Field 'jobtitles.jobtitle' cannot be a zero-length string.
/addingtitle.asp, line 20
a.. Browser Type:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322;
..NET CLR 2.0.40607)
a.. Page:
POST 20 bytes to /addingtitle.asp
a.. POST Data:
submit=Add+Job+Title
Here's my code on the first ASP page (jobsedit.asp):
<%
Dim Conn, RS1
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
server.mappath("jobpostings.mdb")
Set RS1 = Conn.Execute("SELECT jobtitles.jobtitle FROM jobtitles ORDER BY
jobtitles.jobtitle;")
Response.Write("
Add Position to Internal Listing
")
Response.Write("")
Response.Write("
Position not in list? Add It!
")
Response.Write("")
RS1.Close
Set RS1 = Nothing
Set Conn = Nothing
%>
And the code for the second ASP page (addingtitle.asp):
<%
Dim Conn, sql, addtitle
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
server.mappath("jobpostings.mdb")
addtitle = Request.Form("addtitle")
sql = ("INSERT INTO jobtitles VALUES('" & addtitle & "')")
Conn.Execute sql,,129
Set sql = Nothing
Set Conn = Nothing
Response.Redirect("http://webserver/jobsedit.asp")
%>
Like I said, I originally just wanted to do all coding on a single ASP page
for this instead of using two pages but I'm not sure how that would work.
Thanks,
Jim
Re: Multiple html Forms & DB Inserts
am 20.12.2004 16:24:28 von unknown
You're using Request.Form with method=get. Either use Request.Querystring
or method=post.
Also, that error means just what it says, that the column cannot be empty.
I
believe that in Access 2000, when you add a new text field, the default
setting for "Allow Zero Length" is set to no. 2002+ default it to Yes,
thankfully.
You may want to change the option in Access.
Ray at work
"Jim in Arizona" wrote in message
news:er8%23Xaq5EHA.2804@TK2MSFTNGP15.phx.gbl...
>
> Microsoft JET Database Engine (0x80004005)
> Field 'jobtitles.jobtitle' cannot be a zero-length string.
> /addingtitle.asp, line 20
>
Re: Multiple html Forms & DB Inserts
am 20.12.2004 16:48:49 von Jim in Arizona
The first form with the get method wasn't actually my problem. The second
form on that page:
Response.Write("
Position not in list? Add It!
")
Response.Write("
")
That uses the post method. Also, I am actually adding something to that
field before I click the submit button so it can't possibly be a zero length
string, can it?
Thanks Ray.
Jim
"Ray Costanzo [MVP]" wrote in
message news:%2300iBgq5EHA.3840@tk2msftngp13.phx.gbl...
> You're using Request.Form with method=get. Either use Request.Querystring
> or method=post.
>
> Also, that error means just what it says, that the column cannot be empty.
> I
> believe that in Access 2000, when you add a new text field, the default
> setting for "Allow Zero Length" is set to no. 2002+ default it to Yes,
> thankfully.
>
> You may want to change the option in Access.
>
> Ray at work
>
> "Jim in Arizona" wrote in message
> news:er8%23Xaq5EHA.2804@TK2MSFTNGP15.phx.gbl...
>>
>> Microsoft JET Database Engine (0x80004005)
>> Field 'jobtitles.jobtitle' cannot be a zero-length string.
>> /addingtitle.asp, line 20
>>
>
>
>
Re: Multiple html Forms & DB Inserts
am 20.12.2004 16:52:09 von unknown
"Jim in Arizona" wrote in message
news:OkWv3pq5EHA.3336@TK2MSFTNGP11.phx.gbl...
>
> That uses the post method. Also, I am actually adding something to that
> field before I click the submit button so it can't possibly be a zero
length
> string, can it?
I don't know. Response.Write it to see.
Ray at work
Re: Multiple html Forms & DB Inserts
am 20.12.2004 17:02:45 von Jim in Arizona
It appears to be working now, to my amazement. I'm not sure why it just
started working.
Is it possible to incorporate all the code into a single ASP page instead of
jumping all over the place? If I don't specify a page in the form action,
does it just submit the data to itself?
"Jim in Arizona" wrote in message
news:OkWv3pq5EHA.3336@TK2MSFTNGP11.phx.gbl...
> The first form with the get method wasn't actually my problem. The second
> form on that page:
>
> Response.Write("
Position not in list? Add It!
")
> Response.Write("")
>
> That uses the post method. Also, I am actually adding something to that
> field before I click the submit button so it can't possibly be a zero
> length string, can it?
>
> Thanks Ray.
>
> Jim
>
>
>
>
> "Ray Costanzo [MVP]" wrote in
> message news:%2300iBgq5EHA.3840@tk2msftngp13.phx.gbl...
>> You're using Request.Form with method=get. Either use
>> Request.Querystring
>> or method=post.
>>
>> Also, that error means just what it says, that the column cannot be
>> empty.
>> I
>> believe that in Access 2000, when you add a new text field, the default
>> setting for "Allow Zero Length" is set to no. 2002+ default it to Yes,
>> thankfully.
>>
>> You may want to change the option in Access.
>>
>> Ray at work
>>
>> "Jim in Arizona" wrote in message
>> news:er8%23Xaq5EHA.2804@TK2MSFTNGP15.phx.gbl...
>>>
>>> Microsoft JET Database Engine (0x80004005)
>>> Field 'jobtitles.jobtitle' cannot be a zero-length string.
>>> /addingtitle.asp, line 20
>>>
>>
>>
>>
>
>
Re: Multiple html Forms & DB Inserts
am 20.12.2004 17:25:43 von unknown
Yes, you can do that.
Ray at work
"Jim in Arizona" wrote in message
news:OSATxxq5EHA.2624@TK2MSFTNGP11.phx.gbl...
> It appears to be working now, to my amazement. I'm not sure why it just
> started working.
>
> Is it possible to incorporate all the code into a single ASP page instead
of
> jumping all over the place? If I don't specify a page in the form action,
> does it just submit the data to itself?
>
>
> "Jim in Arizona" wrote in message
> news:OkWv3pq5EHA.3336@TK2MSFTNGP11.phx.gbl...
> > The first form with the get method wasn't actually my problem. The
second
> > form on that page:
> >
> > Response.Write("
Position not in list? Add It!
")
> > Response.Write("")
> >
> > That uses the post method. Also, I am actually adding something to that
> > field before I click the submit button so it can't possibly be a zero
> > length string, can it?
> >
> > Thanks Ray.
> >
> > Jim
> >
> >
> >
> >
> > "Ray Costanzo [MVP]" wrote in
> > message news:%2300iBgq5EHA.3840@tk2msftngp13.phx.gbl...
> >> You're using Request.Form with method=get. Either use
> >> Request.Querystring
> >> or method=post.
> >>
> >> Also, that error means just what it says, that the column cannot be
> >> empty.
> >> I
> >> believe that in Access 2000, when you add a new text field, the default
> >> setting for "Allow Zero Length" is set to no. 2002+ default it to Yes,
> >> thankfully.
> >>
> >> You may want to change the option in Access.
> >>
> >> Ray at work
> >>
> >> "Jim in Arizona" wrote in message
> >> news:er8%23Xaq5EHA.2804@TK2MSFTNGP15.phx.gbl...
> >>>
> >>> Microsoft JET Database Engine (0x80004005)
> >>> Field 'jobtitles.jobtitle' cannot be a zero-length string.
> >>> /addingtitle.asp, line 20
> >>>
> >>
> >>
> >>
> >
> >
>
>
Re: Multiple html Forms & DB Inserts
am 20.12.2004 18:15:17 von McKirahan
"Jim in Arizona" wrote in message
news:OSATxxq5EHA.2624@TK2MSFTNGP11.phx.gbl...
> It appears to be working now, to my amazement. I'm not sure why it just
> started working.
>
> Is it possible to incorporate all the code into a single ASP page instead
of
> jumping all over the place? If I don't specify a page in the form action,
> does it just submit the data to itself?
[snip]
Here's a variation of your code in a single page. Watch for word-wrap.
Take a look at Append() and Concat() to build a page with only one
Response.Write().
<% @Language="VBScript" %>
<% Option Explicit
'***
'* 1) Add a jobtitle or display jobtitles
'***
'*
'* Declare Constants
'*
Const cASP = "jobsedit.asp"
Const cMDB = "jobpostings.mdb"
Const cDSN = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
'*
'* Declare Variables
'*
Dim intRST
intRST = 0
Dim strRST
Dim strSQL
Dim arrSTR()
ReDim arrSTR(100)
Dim intSTR
intSTR = 0
Dim strSTR
'*
'* Declare Objects
'*
Dim objADO
Set objADO = Server.CreateObject("ADODB.Connection")
objADO.Open cDSN & Server.MapPath(cMDB)
Dim objRST
'*
'* Processing
'*
If Request.Form("addtitle") <> "" Then
strSQL = "INSERT INTO jobtitles (jobtitle)"
strSQL = strSQL & " VALUES('" & Request.Form("addtitle") & "')"
objADO.Execute strSQL,,129
End If
'*
'*
'*
Append "
Add Position to Internal Listing
"
Append ""
Append "
Position not in list? Add It!
"
Append ""
'*
'* Destroy Objects
'*
Set objRST = Nothing
Set objADO = Nothing
'*
'* Display
'*
Response.Write(Concat())
Sub Append(strSTR)
'** ------------------------------------------------------------ ------------
---'
'* Append()
'*
'* Appends strings to array entries redimensioning as needed; (see
"Concat()").
'** ------------------------------------------------------------ ------------
---'
strSTR = strSTR & ""
If intSTR > UBound(arrSTR) Then
ReDim Preserve arrSTR(UBound(arrSTR) + 100)
End If
arrSTR(intSTR) = strSTR & vbCrLf
intSTR = intSTR + 1
End Sub
Function Concat()
'** ------------------------------------------------------------ ------------
---'
'* Concat()
'*
'* Concatenates array entries into a single string; (see "Append()").
'** ------------------------------------------------------------ ------------
---'
Redim Preserve arrSTR(intSTR)
Concat = Replace(Join(arrSTR, ""),"`",Chr(34))
Erase arrSTR
ReDim arrSTR(100)
intSTR = 0
End Function
%>
Re: Multiple html Forms & DB Inserts
am 20.12.2004 18:55:26 von Jim in Arizona
Whoa!
Thanks for the ideas McKirahan. I admit that a good portion of your code is
a bit beyond me at this time; I'm still scratching my head on the Append()
and Concat() functions, for instance, but it looks a lot better than 200
response.writes. The bulk of the code did give me SEVERAL ideas for going in
different directions on my projects. I will continue to study it and apply
as I can (and as I learn more).
Thanks for your dedication to us newbies!
"McKirahan" wrote in message
news:FMDxd.263358$HA.235909@attbi_s01...
> "Jim in Arizona" wrote in message
> news:OSATxxq5EHA.2624@TK2MSFTNGP11.phx.gbl...
>> It appears to be working now, to my amazement. I'm not sure why it just
>> started working.
>>
>> Is it possible to incorporate all the code into a single ASP page instead
> of
>> jumping all over the place? If I don't specify a page in the form action,
>> does it just submit the data to itself?
>
> [snip]
>
> Here's a variation of your code in a single page. Watch for word-wrap.
>
> Take a look at Append() and Concat() to build a page with only one
> Response.Write().
>
> <% @Language="VBScript" %>
> <% Option Explicit
> '***
> '* 1) Add a jobtitle or display jobtitles
> '***
> '*
> '* Declare Constants
> '*
> Const cASP = "jobsedit.asp"
> Const cMDB = "jobpostings.mdb"
> Const cDSN = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
> '*
> '* Declare Variables
> '*
> Dim intRST
> intRST = 0
> Dim strRST
> Dim strSQL
> Dim arrSTR()
> ReDim arrSTR(100)
> Dim intSTR
> intSTR = 0
> Dim strSTR
> '*
> '* Declare Objects
> '*
> Dim objADO
> Set objADO = Server.CreateObject("ADODB.Connection")
> objADO.Open cDSN & Server.MapPath(cMDB)
> Dim objRST
> '*
> '* Processing
> '*
> If Request.Form("addtitle") <> "" Then
> strSQL = "INSERT INTO jobtitles (jobtitle)"
> strSQL = strSQL & " VALUES('" & Request.Form("addtitle") & "')"
> objADO.Execute strSQL,,129
> End If
> '*
> '*
> '*
> Append "
Add Position to Internal Listing
"
> Append ""
> Append "
Position not in list? Add It!
"
> Append ""
> '*
> '* Destroy Objects
> '*
> Set objRST = Nothing
> Set objADO = Nothing
> '*
> '* Display
> '*
> Response.Write(Concat())
>
> Sub Append(strSTR)
> '** ------------------------------------------------------------ ------------
> ---'
> '* Append()
> '*
> '* Appends strings to array entries redimensioning as needed; (see
> "Concat()").
> '** ------------------------------------------------------------ ------------
> ---'
> strSTR = strSTR & ""
> If intSTR > UBound(arrSTR) Then
> ReDim Preserve arrSTR(UBound(arrSTR) + 100)
> End If
> arrSTR(intSTR) = strSTR & vbCrLf
> intSTR = intSTR + 1
> End Sub
>
> Function Concat()
> '** ------------------------------------------------------------ ------------
> ---'
> '* Concat()
> '*
> '* Concatenates array entries into a single string; (see "Append()").
> '** ------------------------------------------------------------ ------------
> ---'
> Redim Preserve arrSTR(intSTR)
> Concat = Replace(Join(arrSTR, ""),"`",Chr(34))
> Erase arrSTR
> ReDim arrSTR(100)
> intSTR = 0
> End Function
> %>
>
>