Update and Delete

Discussion in 'ASP General' started by Brett_A, Apr 26, 2007.

  1. Brett_A

    Brett_A Guest

    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")
    %>
     
    Brett_A, Apr 26, 2007
    #1
    1. Advertising

  2. Brett_A

    Mike Brind Guest

    "Brett_A" <> wrote in message
    news:...
    > 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.

    --
    Mike Brind
     
    Mike Brind, Apr 26, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    7,854
    elizas
    Apr 27, 2010
  2. HeroOfSpielburg
    Replies:
    1
    Views:
    404
    Alf P. Steinbach
    Aug 6, 2003
  3. Jef Driesen
    Replies:
    1
    Views:
    520
    Gernot Frisch
    Jan 19, 2005
  4. SpreadTooThin

    delete and delete []

    SpreadTooThin, Mar 30, 2007, in forum: C++
    Replies:
    5
    Views:
    327
    James Curran
    Mar 30, 2007
  5. Replies:
    4
    Views:
    485
    James Kanze
    Nov 17, 2008
Loading...

Share This Page