Forum Moderators: open

Message Too Old, No Replies

My asp doesn't work

it is urgent

         

erenshte

3:34 am on Jun 25, 2004 (gmt 0)

10+ Year Member



Here is my question.

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

Krapulator

5:02 am on Jun 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Go into your Internet Options menu (in tools) and click on the advanced tab. Untick the "Show Friendly HTTP Error messages checkbox".

Now navigate to the page again and you should recieve a more detailed error description. Paste it in here if you dont know what it means.

erenshte

1:10 pm on Jun 25, 2004 (gmt 0)

10+ Year Member



Thanks,

It may help to debug.

Erenshte

Easy_Coder

9:44 pm on Jun 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Change this code:
var quantity = request.Form("quantity")

To:

quantity = request.Form("quantity")

erenshte

10:57 pm on Jun 25, 2004 (gmt 0)

10+ Year Member



Thanks,

I realized this error. Will try tonight.

erenshte

12:16 am on Jun 26, 2004 (gmt 0)

10+ Year Member



I have made some changes.
Now I'm receiving an error message that there is
syntactic error in INSERT INTO statement but
references to next two lines.

<!-- #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" -->

duckhunter

1:39 am on Jun 26, 2004 (gmt 0)

10+ Year Member



Syntax looks OK, you must have a missing quote or the likes somewhere in that string. Try printing out the Insert Statement for inspection & the exact error by Resuming execution on Error and trapping the ADO error.

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]

Spooky

4:19 am on Jun 27, 2004 (gmt 0)

10+ Year Member



SQL = "INSERT INTO PersonalList (PersonalID, Alias, GiftName, MerchantURL, PriceRange, Occasion, [Date], Purchased)"

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?

Easy_Coder

4:38 am on Jun 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can look in a couple of areas:

1 - make sure your connection string is valid
2 - Take Duckhunters advice and write your querystring to the screen after it's built. Then stuff the output in query analyzer and see if it fires or if there are issues in the string.

erenshte

4:53 am on Jun 27, 2004 (gmt 0)

10+ Year Member



Thanks a lot.

I'll try tomorrow.

erenshte

erenshte

2:07 pm on Jun 27, 2004 (gmt 0)

10+ Year Member



Haven't try to debug yet.
After fixing type mismatch error I'm getting another one telling that cn object is not defined in the line
cn.execute(NewItemSQL). I have checked login.asp code
that is processed before code I'm debugging and it looks fine to me (cn object is opened there). For some reason it is not passed.

<!-- #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

duckhunter

2:21 pm on Jun 27, 2004 (gmt 0)

10+ Year Member



Since you are including your connection.open code from another file, you must Dim the cn variable in the local page above the include.

<%
Dim cn
%>

<!-- #include file="dbconn.asp" -->
<%
.
.
.

erenshte

7:08 pm on Jun 27, 2004 (gmt 0)

10+ Year Member



Where I have to put Dim cn?
In the beginning of login.asp, or
in the asp file which produces an error.
Should I put it there together with include
dbconn.asp. I think in this case cn will
be redeclared and session will not contain
data gathered from login.

May be I'm wrong. What Dim cn does?

erenshte

duckhunter

10:57 pm on Jun 27, 2004 (gmt 0)

10+ Year Member



Dim is declaring the variable for later us. Good coding always dims variables.

Dim cn in the login.asp page ABOVE the include statement.

erenshte

12:01 am on Jun 28, 2004 (gmt 0)

10+ Year Member



Thanks,

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

Spooky

12:40 am on Jun 28, 2004 (gmt 0)

10+ Year Member



Try this :

<%
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")

erenshte

4:29 am on Jun 28, 2004 (gmt 0)

10+ Year Member



dbconn.asp works fine.
There are two tables in the database.
The first is filled by user registration info -
have checked it many times - and contains user ID,
password, alias and generated Personal Number.
The second part - item records that include
Personal number and alias from first table - doesn't.

The code you are suggesting is the same.

erenshte

duckhunter

6:13 pm on Jun 28, 2004 (gmt 0)

10+ Year Member



Did you Dim cn in AddItemToDb.asp too?

erenshte

9:02 pm on Jun 28, 2004 (gmt 0)

10+ Year Member



No, I didn't. I was thinking that it works as
global declaration and included it to the dbconn.asp
that opens connection to the database.

Should I?

erenshte

duckhunter

2:21 am on Jun 29, 2004 (gmt 0)

10+ Year Member



Yes, you must. Variable names do not pass from an included file to the main file UNLESS they are declared in the main file.

[edit].. and if you Dim the variable in the main file, Don't Dim it again in the included file[/edit]

erenshte

2:33 am on Jun 29, 2004 (gmt 0)

10+ Year Member



Thanks a lot.
Will try.

erenshte

erenshte

2:44 am on Jun 29, 2004 (gmt 0)

10+ Year Member



Sorry, but now I'm getting another error at the same line:
Microsoft VBScript runtime error '800a01a8'

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
%>

Easy_Coder

4:02 am on Jun 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Line 12 on the code you posted looks like:
cn.execute(NewItemSQL)

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")

erenshte

12:45 pm on Jun 29, 2004 (gmt 0)

10+ Year Member



Easy_Coder,

Read my previous messages. Object cn is set before
this code runs.

erenshte

duckhunter

12:52 pm on Jun 29, 2004 (gmt 0)

10+ Year Member



Where's your include statement? You are declaring cn but never creating it.

erenshte

2:35 pm on Jun 29, 2004 (gmt 0)

10+ Year Member



Again, this is 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)
%>

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