Closed Thread Icon

Topic awaiting preservation: inserting data into database (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12325" title="Pages that link to Topic awaiting preservation: inserting data into database (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: inserting data into database <span class="small">(Page 1 of 1)</span>\

 
Ensabanur
Bipolar (III) Inmate

From: KY
Insane since: Nov 2001

posted posted 07-23-2002 02:26

I'm trying to create an insert page for a homework database.
For some reason I can't get it to work. (I've made a bunch of other pages that work fine)
Here's the page

code:
<!--#include file="dsn.asp"-->
<!--#include file="body.asp"-->
<html>
<head>
<title>Untitled</title>
</head>

<body>
<%
sch = request.querystring("whichsch")
teacher = request.querystring("name")
subject = request.querystring("class")
mo = request.querystring("m")
da = request.querystring("d")
ye = request.querystring("y")
assingment = request.querystring("assingment")
mdy = mo & "/" & da & "/" & ye
team = "dont know"
%>
<%
set homework = server.CreateObject("ADODB.RecordSet")
homework.Open "insert into jhomework (sch_teach, sch_class, sch_hw, sch_due) values (" & teacher & "," & subject & "," & assingment & "," & mdy & ")", Conn, 3, 1
%>

<%homework.Close%>
</body>
</html>
<!--#include file="dsn2.asp"-->


The dsn & dsn2 pages open and close the database. I know they work cause I use them for a number of other pages. I get this error when I try to insert the info
________
* Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E10)
[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 3.
/resources/hwinsert2.asp, line 22

________
I get this error if I use more than one word in either input field

* Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E10)
[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 3.
/resources/hwinsert2.asp, line 22

ANy help would be greatly appreciated

Ensa

someoneInverse
Bipolar (III) Inmate

From:
Insane since: May 2002

posted posted 07-23-2002 08:33

on first inspection, I suspect that the error's in the sql statement - the database is probably throwing a fit at you trying to insert text without quoted identifiers
try:
"insert into jhomework (sch_teach, sch_class, sch_hw, sch_due) values ('" & teacher & "', '" & subject & "', '" & assingment & "', '" & mdy & "')",

hth
I:.

Ensabanur
Bipolar (III) Inmate

From: KY
Insane since: Nov 2001

posted posted 07-23-2002 17:39

OK, I did that, now I'm getting another error


Adodb.recordset (0x800a0e78)
operation is not allowed when the object is closed.
/resources/hwinsert2.asp, line 48

I looked this up and is says that it happens when nothing is sent through the querystring, but I fill in each field. Are there any other reasons I get this message?

Thumper
Paranoid (IV) Inmate

From: Deeetroit, MI. USA
Insane since: Mar 2002

posted posted 07-24-2002 02:51

I'm not a coder, but wouldn't the " become \"

Ensabanur
Bipolar (III) Inmate

From: KY
Insane since: Nov 2001

posted posted 07-24-2002 03:43

What do you mean? do you mean something like this '" &teacher& \','\
?

Thumper
Paranoid (IV) Inmate

From: Deeetroit, MI. USA
Insane since: Mar 2002

posted posted 07-24-2002 04:05

(" & teacher & "," & subject & "," & assingment & "," & mdy & ")"

becomes

(\" & teacher & \",\" & subject & \",\" & assingment & \",\" & mdy & \")\",

could be wrong tho...I have had to do this with javascript in PHP includes...

someoneInverse
Bipolar (III) Inmate

From:
Insane since: May 2002

posted posted 07-24-2002 09:38

I think that what it's trying to tell you that it doesn't like doing an insert when you're trying to open a recordset

best thing to do is to scrap the recordset object (since an extra object is kinda superfluous for an insert) and just use
conn.execute("insert into jhomework (sch_teach, sch_class, sch_hw, sch_due) values ('" & teacher & "', '" & subject & "', '" & assingment & "', '" & mdy & "')")

which should hopefully see you in the clear
hth
I:.

Ensabanur
Bipolar (III) Inmate

From: KY
Insane since: Nov 2001

posted posted 07-24-2002 19:00

Working great now. Didn't know i didn't need the recordset object for inserting. Is this true for updating and deleting as well?

Thanks for the help.

someoneInverse
Bipolar (III) Inmate

From:
Insane since: May 2002

posted posted 07-25-2002 07:45

absolutely right about the update and delete there
you only really need the recordset object for select statements or stored procedures with return statements in them


Ensabanur
Bipolar (III) Inmate

From: KY
Insane since: Nov 2001

posted posted 07-26-2002 15:40

Alright, I having trouble figuring out the whole "'s layout. I have this line

code:
homework.open "select * from jhomework where '" & tag & "' = '" & tag2 & "'", Conn, 3, 1


but it doesn't seem to work, the page shows but no entries are grabbed from the database. I tried out putting the values of the fields to the page and they show up correctly. Is there something wrong with the layout of the above line?

Thanks for the help
Ensa

someoneInverse
Bipolar (III) Inmate

From:
Insane since: May 2002

posted posted 07-29-2002 10:46

try:

homework.open "select * from jhomework where " & tag & " = '" & tag2 & "'", Conn, 3, 1

« BackwardsOnwards »

Show Forum Drop Down Menu