Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP - Updating Database Field 3

Status
Not open for further replies.

SamHale

MIS
Mar 7, 2004
71
GB
Hi, thanks for any help in advanced.

I'm trying to create a simple (or atleast what seems simple) form using ASP VB.

It will appear at the bottom of an article, and act much like a rating system.

There we go two option, a Good checkbox, and a Bad checkbox.
(this can change to just two submit buttons if it makes what I want to
achieve easier)

So, I have a database linking to the page with a Table called Rating, and three columns, ID (to link with article), Good and Bad.

So when someone uses the form below the article, say they submit 'Good', I wish for a 1 to appear in the database under good. Then someone else submits 'Good', that 1 increases to 2, then someone else submits 'Good', that 2 increases to 3, etc. and vice versa for the Bad rating.

Can anyone help me?

Many thanks,
Sam.
 
Hi DNG,

Thank you for your input, unfortunately with your sugguestion I am receiving the following error:

Syntax error (missing operator) in query expression 'ID ='.

Any idea?

Many Thanks As Always,
Sam.
 
that means...your querystring varibale is empty...make sure that you are passing it correctly.

-DNG
 
Thanks for the quick reply.

Sorry I am fairly new to ASP.

On the page with the form I have :

Code:
<%
  Dim sql,rsUser
  sql = "SELECT * FROM Users WHERE username = '" & username & "'"
  Set rsUser = Server.CreateObject("ADODB.Recordset")
  rsuser.Open sql, dbconn, 3, 3
  [COLOR=red]Request.QueryString("id")[/color]
%>

This adds onto the end of the page 'profile.asp?id=1' fine.

Then on the thanks page, once the form has been submitted I have this :

Code:
<%
Dim id
id=CInt(request.querystring("id"))
%>

and

Code:
<%
if request.form("rating") <> "" then
select case lcase(request.form("rating"))
    case "good"
               sql="update Users set good=good +1 WHERE id="& request("id")
   RunSQL(sql)
    case "bad"
               sql="update Users set bad=bad +1 WHERE id="& request("id")
         RunSQL(sql)
end select
end if
%>

Thanks for all your help,
Sam.
 
change your query to:

sql="update Users set good=good +1 WHERE id="&id

i am confused here...do you want to use the request.querystring variable id you got from id=CInt(request.querystring("id")) as your database field or as something matching your database field...

-DNG
 
Hi DNG.

In my database I have;

ID - username - good - bad
-1----Admin--------0------0-

So, each username has their own profile, so for example Admin would be profile.asp?id=1 - on the profile.asp page there is a simple form at the bottom, with two check boxes, 'good' and 'bad', when submitted this goes to the thanks.asp page. My thanks.asp page is setup fine to submit the form into the database depending on what was checked, and update the database. So I need it to recognise the number on the end of profile.asp?id=# and use this in the thanks.asp page. To test it I simply used;

Code:
sql="update Users set good=good + 1 WHERE ID = 1

So I know its working.

I tried changing it to what you sugguested but with still no luck.

Thank you for your help, it's greatly apprechiated.
Sam.
 
ok try this:

on the profile page...where you get the variable using

id=CInt(request.querystring("id"))

also do this...just below the above line

Session("id")=id

now on the thanks page....

you dont have to retrieve this value again...just use it directly in your sql query...something like this...

<%
if request.form("rating") <> "" then
select case lcase(request.form("rating"))
case "good"
sql="update Users set good=good +1 WHERE id="&Session("id")
RunSQL(sql)
case "bad"
sql="update Users set bad=bad +1 WHERE id="&Session("id")
RunSQL(sql)
end select
end if
%>

also do a response.write sql to see the actual query...

hope that works

-DNG
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top