Update and Delete

B

Brett_A

Any reason why this code doesn't work? It doesn't generate any errors
but it doesn't update the data.

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
on error resume next

'request variables

report_id = Request.querystring ("report_id")
ad_id = Request.querystring ("ad_id")
report_count = Request.querystring ("report_count")

'reduce report count

report_count = report_count - 1

'create connection

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.open "driver={SQL Server};server=xxxxxxxx"

'delete spam SQL

SQLstmt = "DELETE FROM tbl_reports WHERE report_id=" & report_id & ""

'update spam count SQL

SQLstmt1 = "UPDATE tbl_ads SET "
SQLStmt1 = SQLstmt1 & "report_count='" & report_count & "'"
SQLStmt1 = SQLStmt1 & " WHERE ad_id='" & ad_id & "'"

'execute SQL statements

Conn.execute "SQLstmt"
Conn.execute "SQLstmt1"

'close connection

Conn.close
Set Conn = nothing

'redirction

response.Redirect("alerts.asp")
%>
 
M

Mike Brind

Brett_A said:
Any reason why this code doesn't work? It doesn't generate any errors
but it doesn't update the data.

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
on error resume next

'request variables

report_id = Request.querystring ("report_id")
ad_id = Request.querystring ("ad_id")
report_count = Request.querystring ("report_count")

'reduce report count

report_count = report_count - 1

'create connection

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.open "driver={SQL Server};server=xxxxxxxx"

'delete spam SQL

SQLstmt = "DELETE FROM tbl_reports WHERE report_id=" & report_id & ""

'update spam count SQL

SQLstmt1 = "UPDATE tbl_ads SET "
SQLStmt1 = SQLstmt1 & "report_count='" & report_count & "'"
SQLStmt1 = SQLStmt1 & " WHERE ad_id='" & ad_id & "'"

'execute SQL statements

Conn.execute "SQLstmt"
Conn.execute "SQLstmt1"

'close connection

Conn.close
Set Conn = nothing

'redirction

response.Redirect("alerts.asp")
%>

You have no idea whehter it is producing errors or not (my guess is yes),
because On Error Resume Next will hide them from you. Get rid of that line
first, then try

Conn.execute(SQLstmt)
Conn.execute(SQLstmt1)

If that doesn't work, do

<%
Response.Write SQLstmt : Response.End
%>

to output the SQL to the browser. That way you can check that report_id
contains the value you expect. And do the same for the other statement.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top