Forum Moderators: open
I have a form that is generated every time user clicks on the link under Favorites which is
developed as bookmarklet (Java script). The form is generated by means of Perl script
(cgi code). It is done this way because this script captures URL address user is visiting and
places it into text window of this form. There are some other text fields that should be filled
by user. At that time user is loogged in and is connected to the database. When user press
Submit the data from the form together with some data from the database have to be stored
in the database. Below is the .asp I'm talking about and a line from Perl script that calls this
asp.
<%
var quantity = request.Form("quantity")
for counter = 1 to quantity
session("giftname") = request.Form("giftname")
session("merchanturl") = request.Form("merchanturl")
session("pricerange") = request.Form("pricerange")
session("occasion") = request.Form("occasion")
session("purchased") = "No"
SQL = "INSERT INTO PersonalList (PersonalID, Alias, GiftName, MerchantURL, PriceRange, Occasion, Date, Purchased)"
SQL = SQL & " VALUES ('" & session("personalid") & "','" & session("alias") & "','" & session("giftname") & "','" & session("merchanturl") & "','" & session("pricerange") & "','" & session("occasion") & "','" & Now() & "','" & session("purchased") & "')"
cn.execute(SQL)
next
%>
print "<form name='addwish' method='POST' action='http://www.wishtreeonline.com/AddWishToDb.asp'>\n";
Running it on the site produces an error "HTTP 500 - Internal server error" and tells that there is a
problem with the page you are trying to reach.
Need help as soon as possible
Regards, erenshte
<!-- #include file="dbconn.asp" -->
<%
quantity = request.Form("quantity")
for counter = 1 to quantity
session("giftname") = request.Form("giftname")
session("merchanturl") = request.Form("merchanturl")
session("pricerange") = request.Form("pricerange")
session("occasion") = request.Form("occasion")
session("purchased") = "No"
SQL = "INSERT INTO PersonalList (PersonalID, Alias, GiftName, MerchantURL, PriceRange, Occasion, Date, Purchased)"
SQL = SQL & " VALUES ('" & session("personalid") & "','" & session("alias") & "','" & session("giftname") & "','" & session("merchanturl") & "','" & session("pricerange") & "','" & session("occasion") & "','" & Now() & "','" & session("purchased") & "')"
cn.execute(SQL)
next
%><!-- #include file="dbconnclose.asp" -->
On Error Resume Next
Response.Write "SQL To Execute: " & SQL & "<BR>"
cn.execute(SQL)
If cn.Errors.Count > 0 Then
If cn.Errors.Item(0).Number <> 0 Then
Response.Write "SQL Error: " & cn.Errors.Item(0).Description
End If
End If
[edit]BTW, that's alot of Session variables. How many others are you using? More than 4-5 per user won't scale to support 100's of simultaneous users. Why not use cookies for Personal preferences?[/edit]
Date is a reserved word.
Assuming access, youll do this :
on") & "',#" & Now() & "#,'" & session
Or
on") & "',Now(),'" & session
Im not too sure why youd loop based on quantity though?
<!-- #include file="dbconn.asp" -->
<%
username = request.form("username")
password = request.form("password")
SQL = "SELECT * FROM Personal WHERE username = '" & username & "' AND password = '" & password & "'"
set rs = cn.execute(SQL)
if rs.eof then
response.redirect "login.asp?error=1"
else
session("loggedin") = true
session("personalid") = rs("PersonalID")
session("alias") = rs("Alias")
session("username") = rs("Username")
SQL = "UPDATE Personal SET TimesLoggedIN = TimesLoggedIn + 1, LastLogin = Now() WHERE Alias = '" & session("alias") & "'"
set ps = cn.execute(SQL)
response.write "<script>window.open(""buildmain.htm"", ""_top"");</script>"
ps.close
set ps = nothing
rs.close
set rs = nothing
end if
%>
dbconn.asp:
<%
set cn=Server.CreateObject("adodb.Connection")
filePath = Server.MapPath("data/dbwtpersonal.mdb")
cn.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source="+filePath)
%>
To Spooky: same record is duplicated quantity times.
Many thanks, erenshte
May be I'm wrong. What Dim cn does?
erenshte
This what I was thinking. But I was confused because
in dbconn.asp I already have set cn.... statement.
Anyway, after I followed your advise, I still am getting the following message when AddItemToDb.asp runs
Microsoft VBScript runtime error '800a01a8'
Object required: 'cn'
/AddItemToDb.asp, line 11
It still doesn't pass it for some reason.
erenshte
<%
set cn=Server.CreateObject("adodb.Connection")
filePath = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source="& Server.MapPath("data/dbwtpersonal.mdb")
cn.Open filePath
%>
Failing that response.write the path to see that the database is correct
response.write Server.MapPath("data/dbwtpersonal.mdb")
The code you are suggesting is the same.
erenshte
Object required: ''
/AddWishToDb.asp, line 12
Following your advise the AddWishToDb.asp now is:
<%
Dim cn
quantity = request.Form("quantity")
for counter = 1 to quantity
giftname = request.Form("giftname")
merchanturl = request.Form("merchanturl")
pricerange = request.Form("pricerange")
occasion = request.Form("occasion")
purchased = "No"
NewItemSQL = "INSERT INTO PersonalList (PersonalID, Alias, GiftName, MerchantURL, PriceRange, Occasion, [Date], Purchased)"
NewItemSQL = NewItemSQL + "VALUES ('" & session("personalid") & "', '" & session("alias") & "','" & giftname & "','" & merchanturl & "','" & pricerange & "','" & occasion & "',Now(),'" & purchased & "')"
cn.execute(NewItemSQL)
next
%>
The error msg is indicating that you have not spun up a connection object with the name of cn.
Somewhere you should have:
Set cn = Server.CreateObject("ADODB.Connection")
Do you have that somewhere but just didn't post it? If not place it right after you dimension cn:
Dim cn
Set cn = Server.CreateObject("ADODB.Connection")
<%
set cn=Server.CreateObject("adodb.Connection")
filePath = Server.MapPath("data/dbwtpersonal.mdb")
cn.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source="+filePath)
%>
It runs from login_proc.asp and opens a session.
AddWishToDB.asp runs under same session. If I
include dbconn.asp into it, then the session opened before is overwritten and I cannot get data passed
from login (personalid and alias).
erenshte