Print Page | Close Window

Article rating script problem

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=1327
Printed Date: 29 March 2026 at 1:57pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Article rating script problem
Posted By: Nischint
Subject: Article rating script problem
Date Posted: 25 March 2003 at 11:29am

I'm trying to use the article rating system, which was written by Annette Tenison. I've made quite a few modifications to it to suit my requirements, especially since the article explains how the script works with a DSN connection, and I'm using a DSN-less one.

The problem is in the rate.asp page, which takes the variables from the articles.asp page entered by the user, and writes them to the database. I'm facing some problems with this.

The code snippet (line 64 of the page) I'm talking about is:

conn.Execute "INSERT INTO ratings(rating, ip, cdId) VALUES(" & rating & ", '" & visitorIP & "', " & cdId & ")"

While using this, the asp page does not send the data properly to the db, and I don't think the db receives it either. I get the following error.

Error Type:
Microsoft VBScript runtime (0x800A01A8)
Object required: 'driver={Microsoft Ac'
/wwwroot/articles/rate.asp, line 64


I tried using a DSN-less connection and:

sql="insert into ratings SET rating='" & rating & "',ip='" & visitorIP & "',id='" & id & "' where ratingid=" & request("ratingid")

and

sql="update ratings SET rating='" & rating & "',ip='" & visitorIP & "',id='" & id & "' where ratingid=" & request("ratingid")

But none of them seem to work. Help? I'm attaching the asp files I'm using.

One last thing. The database has two tables, "articles" and "ratings" and in all the asp files, I'm constantly opening one table, then closing it, then opening the other one. Maybe that's the problem, I dunno.

I've posted the same query on another site, hoping to speed up the responses. I also attached the asp files I'm using, but that function doesn't seem to be on this forum. So please use the link below to get the files.

http://www.devarticles.com/forum/attachment.php?s=&postid=13195 - http://www.devarticles.com/forum/attachment.php?s=&postid=13195




Replies:
Posted By: MorningZ
Date Posted: 25 March 2003 at 1:11pm
first off.

sql="insert into ratings SET rating='" & rating & "',ip='" & visitorIP & "',id='" & id & "' where ratingid=" & request("ratingid")

isn't proper syntax for INSERT, that will never ever work

second, for your error
Error Type:
Microsoft VBScript runtime (0x800A01A8)
Object required: 'driver={Microsoft Ac'
/wwwroot/articles/rate.asp, line 64

you either (1) have the connection string wrong, or (2) don't have a connection to the DB open...

it'd be helpful if you say exactly what line 64 is, but since you fail to do so, its not possible to help further

-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: Nischint
Date Posted: 25 March 2003 at 7:42pm
Line 64 on my code is the one I posted:

conn.Execute "INSERT INTO ratings(rating, ip, cdId) VALUES(" & rating & ", '" & visitorIP & "', " & cdId & ")"

I think I have the second problem, where I don't have the connection to the DB open yet, I'm not sure. Did you check the attached files?


Posted By: XCSindia
Date Posted: 26 March 2003 at 4:29am
Did you create the Connection Object before executing the SQL statement.I could not find the Attached file you are talking about.Please paste the code written in that file here so that we can have a look at that and post more targeted help.

-------------
Manish Bhalla
Director-XCSindia


Posted By: Nischint
Date Posted: 26 March 2003 at 7:18am

This is the full code I'm using:

<%

dim cn, rs

set cn = server.createObject("ADODB.Connection")
set rs = server.CreateObject("ADODB.Recordset")

function makeDBConnection()

'set the file path to the database
dbPath="articles.mdb"

err.clear
on error resume next
' connect to the database
cn="driver={Microsoft Access Driver (*.mdb)};"
cn=cn & "dbq=" & server.mappath(dbPath)

 if err then
  Response.Write("<h3>Error Trapped</h3> while creating DB connection<p>" & err.description)
  Response.End
 end if

end function


function makeRS(SQL)

'Create a recordset
 on error resume next
  rs.Open sql, CN

 if err then
  Response.Write("<p>Error Trapped<p>" & err.description & "<p>while reading from DB<p> " & SQL)
  Response.End
 end if

 makeRS=rs

end function

%>
<% makeDBConnection() %>
<%
 dim id
 dim visitorIP
 dim rating
 dim cookie
 dim cookieRated

 id = Request.Form("id")
 rating = Request.Form("rating")
 visitorIP = Request.ServerVariables("REMOTE_ADDR")
 cookie = Request.Cookies("rate_" & id)

 rs.activeconnection = cn
 
 if cookie = "" then
  cookieRated = false
 else
  cookieRated = true
 end if

 if rating = "" then
 'Invalid rating
 %>
  <b>You must select a rating first!!</b>
 <%
 else
 'Valid rating, make sure visitor hasn't already voted by checking the ratings table
 
  rs.open "select count(*) from ratings where ip='" & visitorIP & "' and id=" & id
  if rs.Fields(0).Value = 0 then
   if cookieRated = false then
    'Visitor hasn't rated yet, let's add it
    cn.Execute "INSERT INTO ratings(rating, ip, id) VALUES(" & rating & ", '" & visitorIP & "', " & id & ")"
    Response.Cookies("rate_" & id) = true
    Response.Cookies("rate_" & id).expires = Date() + 30
    %>
     <b>Thanks for the rating.</b>
    <%
   else
    'Visitor has already rated this article
    %>
    <b>Hey, you've already rated this article.</b>
    <%
   end if
  else
   'Visitor has already rated this article
   %>
<b>Hey, you've already rated this article.</b>
   <%
  end if
 end if

%>

The code in green is an include file, called "db.asp", but I've added that code too. The code in red is my "rate.asp" file, and the snippet in blue is the one I'm having a problem with.

The original code was written for a DSN connection, whereas I have customized it for my DSNless connection. That one line of code:

cn.Execute "INSERT INTO ratings(rating, ip, id) VALUES(" & rating & ", '" & visitorIP & "', " & id & ")"

is the biggest culprit. And it gives me the following error:

Error Type:
Microsoft VBScript runtime (0x800A01A8)
Object required: 'driver={Microsoft Ac'


It's a DSN command, and I have no idea what to put in there for a DSNless command. I've tried using:

sql="insert into ratings SET rating='" & rating & "',ip='" & visitorIP & "',id='" & id & "' where ratingid=" & request("ratingid")

and

sql="update ratings SET rating='" & rating & "',ip='" & visitorIP & "',id='" & id & "' where ratingid=" & request("ratingid")

but neither seems to work, since although the page is processed, the data is not added to the database.

Hope it's clear enough now, since I've posted the full code.


If you'd like to see the very original script, please do follow this url: http://www.devarticles.com/art/1/141 - http://www.devarticles.com/art/1/141



Posted By: MorningZ
Date Posted: 26 March 2003 at 7:58am
first off... if there is something WORSE to do than "on Error Resume Next" everywhere, i don't what is....

you'll never ever be able to properly debug using the "skip error" method

second, you have the code:

' connect to the database
cn="driver={Microsoft Access Driver (*.mdb)};"
cn=cn & "dbq=" & server.mappath(dbPath)


that is not a connection to the database, all you did was assign a string that holds the location of the databse, it is not a connection itself, you must open a connection, a la

Dim objConn
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open cn '<<== here's where the connection string goes


and from there on out

objConn.Execute SQL Code
and
Recordset.Open SQL String, objConn



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: Nischint
Date Posted: 26 March 2003 at 12:12pm
Thanks, MorningZ, once again. It worked most excellently


Posted By: jcw568s
Date Posted: 10 June 2003 at 12:18pm

Could someone post a working version of this code? I would like to use it on my article page. Thanks

 

J




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net