Need Help. - Can't find my error

G

Gaby

Hi guys,
I have this ASP code that is a little long to post so but you can
download it off of
http://whatthedeuce.net/Form.asp

I cant find out what my error is. I know it is not in my Access
because I have tested my query and it works fine. but whenever i try
to submit from the page the imformation doesnt go thorugh. on a side
note, if i hit refresh it tells me it cannot refresh without sending
the information. i dont know if this would help any. please help me
if you guys can. i need this for a very important research project at
my university.

Thanks again,
Gabriel
 
B

Bob Barrows [MVP]

Gaby said:
Hi guys,
I have this ASP code that is a little long to post so but you can
download it off of
http://whatthedeuce.net/Form.asp

I cant find out what my error is. I know it is not in my Access
because I have tested my query and it works fine. but whenever i try
to submit from the page the imformation doesnt go thorugh. on a side
note, if i hit refresh it tells me it cannot refresh without sending
the information. i dont know if this would help any. please help me
if you guys can. i need this for a very important research project at
my university.
You would be better off creating a small repro page that we can run
ourselves. Strip out everything that is not related to the symptom you are
experiencing and post it here. Provide details abot the database tables and
queries.
 
G

Gaby

Heres the simplified version of the code. I will only include the code
showing five questions, when the real one has over 120.....


--

<HTML>
<HEAD>
<TITLE>Survey: Traits and IT </TITLE>
<Style type="text/css"> body { Color: black; background: 99CCFF; }
body { margin-left: 5%; margin-right: 5% }
h1 { margin-left: -8%; }
h2, h3, h4, h5 { margin-left: -4% }
h2 { margin-top: 8em; margin-bottom: 3em; }
p { text-indent: 2em; margin-top: 0; margin-bottom: 0; }
body { font-family: Arial, sans-serif; }
h1, h2 { font-family: Arial, Verdana, sans-serif; }
div.box { border: solid; border-width: thin; width: 100% }
div.color { background: rgb (204, 204, 255); padding: 0.5em; border:
none ; }
</Style>
</HEAD>
<BODY>
<FORM name="frmtrial_IPC" method="post" action="FormResponse.asp">
<P>The following is the draft for a survey page.</P>
<br>
<Select name="Instructor">
<option value="" selected>Select Instructor</option>
<option value="Ammons">
Ammons</option>
<option value="Norton">
Norton</option>
<option value="OTHER">
Other</option>
</Select>
&nbsp; &nbsp;
<Select name="Semester">
<option value="" selected>Select Semester</option>
<option value="Spring2006">
Spring , 2006
</option>
<option value="SummerI2006">
Summer I , 2006</option>
<option value="SummerII2006">
Summer II , 2006</option>
<option value="Fall2006">
Fall , 2006</option>
</Select>
Class Roster #: <input type="text" size="12" maxlength="6"
name="roster" id="roster">
<br>
<Select name="Gender">
<option value="" selected>Select Gender</option>
<option value="Male"> Male</option>
<option value="Female"> Female</option>

</Select>
<input type="text" name="text1" id="text1">
<br>
<br>
<input type="password" size="10" maxlength="15" name="password"
value="MyPassword" id="password">
<HR>
<BR>
<BR>
<I><B>Instructions:</I></B> Check (click) the box of each of the
following
words or phrases that would usually describe you. If you
unintentionally or
mistakenly a check a box, you may click it to uncheck.
<BR>
<BR>
01. <input type="checkbox" id="1_AbleToGiveOrders"
name="1_AbleToGiveOrders" value="1">
<label for="AbleToGiveOrders">Able to give orders</label>
<BR>
02. <input type="checkbox" id="2_Appreciative" name="2_Appreciative"
value="1">
<label for="Appreciative">Appreciative</label>
<BR>
03. <input type="checkbox" id="3_Apologetic" name="3_Apologetic"
value="1">
<label for="Apologetic">Apologetic</label>
<BR>
04. <input type="checkbox" id="4_AbleToTakeCareOfSelf"
name="4_AbleToTakeCareOfSelf" value="1">
<label for="AbleToTakeCareOfSelf">Able to take care of self</label>
<BR>
<BR>
05. <input type="checkbox" id="5_AcceptsAdviceReadily"
Name="5_AcceptsAdviceReadily" value="1">
<label for="AcceptsAdviceReadily">Accepts advice readily</label>
<BR>

......(and so on for all 120 questions)...

<BR>
<Center>
&nbsp; <INPUT TYPE="submit" value="Submit" name="Action" />
</FORM>
<%
On Error Resume Next
If Request.Form("Action") = "Submit" Then
strFilePath = server.MapPath("hgb_experiment.mdb")
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFilePath


conn.open strConn
n1 = clng(Request.Form("Roster"))

n2 = Request.Form("Instructor")

n3 = Request.Form("Semester")

n4 = Request.Form("Gender")

n5 = clng(Request.Form("Password"))


p1 = cint(Request.Form("1_AbleToGiveOrders"))

p2= cint(Request.Form("2_Appreciative"))

p3= cint(Request.Form("3_Apologetic"))

p4= cint(Request.Form("4_AbleToTakeCareOfSelf"))


p5= cint(Request.Form("5_AcceptsAdviceReadily"))

....(and so on)...


conn.qInsertRecord n1, n2, n3, n4, n5, p1, p2, p3, p4, p5
Response.Write "Your record has been added"

End If

%>
<! ----- FORM CLOSED ---- FORM CLOSED ---- />
</CENTER>
</BODY>
</HTML>
 
B

Bob Barrows [MVP]

Gaby said:
Heres the simplified version of the code. I will only include the
code showing five questions, when the real one has over 120.....

Strip it down even more. We don't need to see any html. Just extract the
code used to communicate with the database and show us that, along with the
details of thetables involved in your queries (field names and datatypes)
 
M

Mike Brind

<%
On Error Resume Next

First thing to do Gaby, is to get rid of this line. If there are
errors, this line is hiding them. Run the page without this, and see
if you get an error message. If you do, and don't understand it, post
it here, in full, together with the line that causes the error.
 
M

Mike Brind

Mike said:
First thing to do Gaby, is to get rid of this line. If there are
errors, this line is hiding them. Run the page without this, and see
if you get an error message. If you do, and don't understand it, post
it here, in full, together with the line that causes the error.

Actually, I suspect the cause of the problem will be an error relating
to clng or cint. Here's a section from your code:

<%
....

p1 = cint(Request.Form("1_AbleToGiveOrders"))
p2= cint(Request.Form("2_Appreciative"))
p3= cint(Request.Form("3_Apologetic"))
p4= cint(Request.Form("4_AbleToTakeCareOfSelf"))
....

%>

If any of these are unchecked, they will evaluate to an empty string.
You can't convert that to an int. That will raise an error.
Consequently, when you get to the conn.qInsertRecord line, none of the
parameters are set.
 
G

Gaby

Mike said:
First thing to do Gaby, is to get rid of this line. If there are
errors, this line is hiding them. Run the page without this, and see
if you get an error message. If you do, and don't understand it, post
it here, in full, together with the line that causes the error.

I dont get any errors. I just nocite that window when I refresh.

Here is the query I run
It is called: qInsertRecord
Heres a short version. It just looks like:
INSERT INTO Research ( Roster, Instructor, [Password],
1_AbletoGiveOrders, 2_Appreciative )
VALUES ([n1], [n2], [n5], [p1], [p2]);

My table is called Research. and My Acess DB is called
hgb_experiment.mdb
 
B

Bob Barrows [MVP]

Gaby said:
Mike said:
First thing to do Gaby, is to get rid of this line. If there are
errors, this line is hiding them. Run the page without this, and see
if you get an error message. If you do, and don't understand it,
post it here, in full, together with the line that causes the error.

I dont get any errors. I just nocite that window when I refresh.

Here is the query I run
It is called: qInsertRecord
Heres a short version. It just looks like:
INSERT INTO Research ( Roster, Instructor, [Password],
1_AbletoGiveOrders, 2_Appreciative )
VALUES ([n1], [n2], [n5], [p1], [p2]);
What are the datatypes of these fields? What is the significance of the
parameter names?
My table is called Research. and My Acess DB is called
hgb_experiment.mdb

OK, so when you test this query in Access, it works correctly, right? That
means there's a problem running it from ASP. Create a small page to test it,
like this:

<%
dim cn, ar(4)
ar(0)=<hard-coded value appropriate for Roster>
ar(1)=<hard-coded value appropriate for Instructor>
ar(2)=<hard-coded value appropriate for Password>
ar(3)=<hard-coded value appropriate for 1_AbletoGiveOrders>
ar(4)=<hard-coded value appropriate for 2_Appreciative>
set cn=createobject("adodb.connection")
cn.open "provider=microsoft.jet.oledb.4.0;" & _
"data source=" & server.mapppath("hgb_experiment.mdb")
cn.qInsertRecord ar(0),ar(1),ar(2),ar(3),ar(4)
cn.close:set cn=nothing
%>


Run this page. Do you get any errors? Open your database in Access and
verify that the record got inserted. Did it? If so, then we know there's no
problem running the query and the problem is elsewhere, most likely with how
you are handling the data submitted via the form. Anways, try the above test
and let us know the result.
 
D

Dave Anderson

Gaby said:
Heres the simplified version of the code...

I have a few observations, some of which are unlikely to be the problem.
Nevertheless, I offer them:


01. <input type="checkbox" id="1_AbleToGiveOrders"
name="1_AbleToGiveOrders" value="1">
<label for="AbleToGiveOrders">Able to give orders</label>

Your FOR attribute value does not match your ID attribute value, in
violation of the HTML specification:
http://www.w3.org/TR/html401/interact/forms.html#adef-for

Furthermore, your ID attributes do not conform to the requirement that they
begin with a letter:
http://www.w3.org/TR/html401/types.html#type-id

These are repeated with questions 2-5.


<INPUT TYPE="submit" value="Submit" name="Action" />

More of a warning than anything, but you might want to avoid using the name
"Action" here, as it can lead you into a troubleshooting nightmare if you
confuse form.Action with form.action.


On Error Resume Next

If you insist on using this, make sure to check the Err Object
(http://msdn.microsoft.com/library/en-us/script56/html/70223b47-3bb6-4b15-b967-f3f8082fdbfe.asp)
at strategic places:

conn.open strConn
If Err.Number > 0 Then
Response.Write("Problem connecting!")
...
Err.Clear
End If


<input type="text" size="12" maxlength="6" name="roster"
id="roster"> <--- I have taken this out of sequence
n1 = clng(Request.Form("Roster"))

If you have not validated the contents of Request.Form("Roster").Item, then
CLng is prone to failure. Ditto for CInt further down.


conn.qInsertRecord n1, n2, n3, n4, n5, p1, p2, p3, p4, p5

You never reached this point, IMO.
 
G

Gaby

OK, so when you test this query in Access, it works correctly, right? That
means there's a problem running it from ASP. Create a small page to test it,
like this:

<%
dim cn, ar(4)
ar(0)=<hard-coded value appropriate for Roster>
ar(1)=<hard-coded value appropriate for Instructor>
ar(2)=<hard-coded value appropriate for Password>
ar(3)=<hard-coded value appropriate for 1_AbletoGiveOrders>
ar(4)=<hard-coded value appropriate for 2_Appreciative>
set cn=createobject("adodb.connection")
cn.open "provider=microsoft.jet.oledb.4.0;" & _
"data source=" & server.mapppath("hgb_experiment.mdb")
cn.qInsertRecord ar(0),ar(1),ar(2),ar(3),ar(4)
cn.close:set cn=nothing
%>


Run this page. Do you get any errors? Open your database in Access and
verify that the record got inserted. Did it? If so, then we know there's no
problem running the query and the problem is elsewhere, most likely with how
you are handling the data submitted via the form. Anways, try the above test
and let us know the result.

Since you are running the existing query I have do I have to change
that as well to include ar(0), ar(1), ect? also, should i put the hard
coded values in "" or not? Let me know so I can run the test page like
you say.

Thanks again everyone for the help.
Im really trying to get this done ASAP so I can begin experiments next
week.

Gabriel
 
B

Bob Barrows [MVP]

Gaby said:
Since you are running the existing query I have do I have to change
that as well to include ar(0), ar(1), ect?

?
No. Run it as is. This is intended to test the ability to pass values to
your parameterized query and run it without error.
also, should i put the hard
coded values in "" or not?

Of course! The next step after successfully testing this is to modify it to
accept data submitted from your form.
 
G

Gaby

Bob,

<%
dim cn, ar(4)
ar(0)=<"222334444">
ar(1)=<"Norton">
ar(2)=<"581371">
ar(3)=<"3">
ar(4)=<"3">
set cn=createobject("adodb.connection")
cn.open "provider=microsoft.jet.oledb.4.0;" & _
"data source=" & server.mapppath("hgb_experiment.mdb")
cn.qInsertRecord ar(0),ar(1),ar(2),ar(3),ar(4)
cn.close:set cn=nothing
%>

Tested the page above and I got
Microsoft VBScript compilation error '800a03ea'

Syntax error

/web/test/hbrown/test.asp, line 4

ar(0)=<"222334444">
-------------------^
 
G

Gaby

Ok,
I removed the <>

It now looks like...
<%
dim cn, ar(4)
ar(0)="222334444"
ar(1)="Norton"
ar(2)="581371"
ar(3)="3"
ar(4)="3"
set cn=createobject("adodb.connection")
cn.open "provider=microsoft.jet.oledb.4.0;" & _
"data source=" & server.mapppath("hgb_experiment.mdb")
cn.qInsertRecord ar(0),ar(1),ar(2),ar(3),ar(4)
cn.close:set cn=nothing
%>

I ran it and got this error
Microsoft VBScript runtime error '800a01b6'

Object doesn't support this property or method: 'server.mapppath'

/web/test/hbrown/test.asp, line 10


Let me know you guys think I should do next. Im hopng to get it
running by Monday so Ill be tinkering with it all afternoon.

Thanks again,
Gabriel
 
B

Bob Barrows [MVP]

Gaby said:
Ok,
I removed the <>

It now looks like...
<%
dim cn, ar(4)
ar(0)="222334444"
ar(1)="Norton"
ar(2)="581371"
ar(3)="3"
ar(4)="3"

Nothing to do with the error you are getting of course, but: what are the
datatypes of the fields in this example? If they are Text, then you are
correct to put quotes around the numeric values. If they are Number fields,
you should NOT put quotes around the values when assigning them to the array
elements. You should be passing strings to Text parameters and numbers to
numeric parameters.
set cn=createobject("adodb.connection")
cn.open "provider=microsoft.jet.oledb.4.0;" & _
"data source=" & server.mapppath("hgb_experiment.mdb")
cn.qInsertRecord ar(0),ar(1),ar(2),ar(3),ar(4)
cn.close:set cn=nothing
%>

I ran it and got this error
Microsoft VBScript runtime error '800a01b6'

Object doesn't support this property or method: 'server.mapppath'

Too many p's in mappath. Could have been a typo on my part
 
G

Gaby

OK!!! I think we are getting somewhere. It was a typo I overlooked.

<%
dim cn, ar(4)
ar(0)="222334444"
ar(1)="Norton"
ar(2)="581371"
ar(3)="3"
ar(4)="3"
set cn=createobject("adodb.connection")
cn.open "provider=microsoft.jet.oledb.4.0;" & _
"data source=" & server.mappath("hgb_experiment.mdb")
cn.qInsertRecord ar(0),ar(1),ar(2),ar(3),ar(4)
cn.close:set cn=nothing
%>

The information was passed into the table!!

Whats the next step?
Im getting excited. Hopefully, I can get it the form working.
 
B

Bob Barrows [MVP]

Gaby said:
OK!!! I think we are getting somewhere. It was a typo I overlooked.

<%
dim cn, ar(4)
ar(0)="222334444"
ar(1)="Norton"
ar(2)="581371"
ar(3)="3"
ar(4)="3"

Again, are these numbers going into Text fields? If not, then you need to
remove the quotes:

ar(4) = 3
set cn=createobject("adodb.connection")
cn.open "provider=microsoft.jet.oledb.4.0;" & _
"data source=" & server.mappath("hgb_experiment.mdb")
cn.qInsertRecord ar(0),ar(1),ar(2),ar(3),ar(4)
cn.close:set cn=nothing
%>

The information was passed into the table!!

Whats the next step?
Im getting excited. Hopefully, I can get it the form working.
OK, now you understand (I hope) the mechanism for passing the data to the
parameters in your saved query. The idea is to pass them in the same order
in which they appear in your saved query, which you can now confirm has been
accomplished.

Let's move on to incorporating it into your existing form ... but let's do
it in small steps. I assume you have a form where the user enters and
submits the data. So change the action property of the form tag to make it
submit to this test page. Then, in this test page, change the hard-coded
values to references to the form variables coming from the submission.

ar(0) = Request.Form("name of variable")

Run your form, enter some test data, submit it, and verify that it gets
added into your database. I would suggest adding this code to the test page,
right after the line that executes the saved query:

dim sql, cmd, arParms, html
sql="Select Roster, Instructor, [Password]," & _
"1_AbletoGiveOrders, 2_Appreciative " & _
"From Research Where Roster = ?"
arParms=Array(ar(0))
set cmd=createobject("adodb.command")
cmd.commandtype=1 'adCmdText
cmd.commandtext=sql
set cmd.activeconnection=cn
set rs=cmd.execute(,arParms)
if rs.eof then
response.write "No record was inserted"
else
response.write "<table border=""1"" "
response.write "style=""border-collapse:collapse;""><tr>"
response.write "<th>Roster</th>"
response.write "<th>Instructor</th>"
response.write "<th>Password</th>"
response.write "<th>1_AbletoGiveOrders</th>"
response.write "<th>2_Appreciative</th></tr><tr><td>"
html=rs.getstring(2,,"</td><td>","</td></tr><tr><td>")
html=left(html,len(html) - 8)
response.write html
response.write "</table>"
end if
rs.close:set rs=nothing

Once you have that accomplished, the next step will be to add some code to
validate that the user enters data that is correct. Users sometime make
mistakes an do things like entering alpha characters when you are expecting
numbers, or entering nothing at all. And some users will maliciously enter
data designed to either damage your database or break into it. See
http://mvp.unixwiz.net/techtips/sql-injection.html
http://www.sqlsecurity.com/DesktopDefault.aspx?tabid=23

You need to deal with these situations before you even create your
connection object ... but, one step at a time.
 
G

Gaby

I tried what you said and it worked. The only thing I need to add if
making it ok to leave data out. I would get a error if I left
checkboxes unchecked. During the actual survey, it will be ok for
students to leave boxes blank if they do not apply. Is there anyway to
code it so that incomplete data is allowed?

Thanks again,
Gabriel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,263
Messages
2,571,062
Members
48,769
Latest member
Clifft

Latest Threads

Top