Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: Adding Numbers

  1. #1
    Regular Coder Baleric's Avatar
    Join Date
    Feb 2005
    Location
    Australia
    Posts
    332
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Adding Numbers

    hihi ppl, im having trouble adding numbers to a database,
    i have a news page where i would like to have a hit counter.
    And like every other hit counter i would like to add a +1 when someone comes in to view that news,
    now here is my code.

    Code:
    <%	Set cnnLogin = Server.CreateObject("ADODB.Connection")
    	cnnLogin.Open("DRIVER={Microsoft Access Driver (*.mdb)};" _
    		& "DBQ=" & Server.MapPath("SamDave.mdb"))
    %>
    
    <%	cnnLogin.execute("UPDATE _news SET news_views = '" &  1  & "' WHERE ID = '" & request.QueryString("show") & "'") %>
    i also have the database as a number instead of text, cause i was told that it should add a 1 automatically to the existing number...
    appreciate any comments

    thanx -baleric

  • #2
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Since it is a number you do not need single quotes around it. Your query would look like:

    Code:
    cnnLogin.execute("UPDATE _news SET news_views = news_views + 1 WHERE ID = '" & request.QueryString("show") & "'")
    You can add do the math directly in the SQL query itself.
    OracleGuy

  • #3
    Regular Coder
    Join Date
    May 2003
    Location
    Stockholm, Sweden
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I suggest you too change ur databas-connection to this:

    Code:
    <% Set Conn = Server.CreateObject("ADODB.Connection") 
         Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("urdatabase.mdb") %>
    This connection is the "new" Microsoft JET standard.. it works better.

  • #4
    Regular Coder Baleric's Avatar
    Join Date
    Feb 2005
    Location
    Australia
    Posts
    332
    Thanks
    0
    Thanked 0 Times in 0 Posts
    now im copping this error .

    Error Type:
    Microsoft JET Database Engine (0x80040E07)
    Data type mismatch in criteria expression.
    /SamDave/Pages/ShowNews.asp, line 55

    this is my line 55 now.

    <% cnnLogin.execute("UPDATE _news SET news_views = news_views + 1 WHERE ID = '" & request.QueryString("show") & "'") %>

    thanks for hlp guys

  • #5
    Regular Coder
    Join Date
    Sep 2004
    Posts
    152
    Thanks
    0
    Thanked 0 Times in 0 Posts
    @Baleric,
    In the table you are updating, is ID a numeric value? If so, get rid of the ' before and after the request string.

    ...WHERE ID = " & request.QueryString("show") & ""...

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    This is double-posted in this forum and was already answered there.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •