check db for records...not workin

Discussion in 'C#' started by grobar, Jun 4, 2006.

  1. #1
    supposed to check for record.

    simply returns the "not exists" even when record DOES exust

    
    dim db, sql_check
    
    Set db = Server.CreateObject("ADODB.Connection")
    db.Open strdbpath
    
    sql_check = "select email from newsletter where email =' & inventory & '"	
    
    Set rs = db.Execute(sql_check)
    %>
    							
    
    <%
    If rs.eof then 
    response.write ("email not there")
    else
    response.write ("email already in db")
    end if
    %>
    
    Code (markup):

     
    grobar, Jun 4, 2006 IP
  2. jaymcc

    jaymcc Peon

    Messages:
    139
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Your code looks ok, are you able to do a response.write of the inventory variable, just to be sure it's using what you expect?

    Jay
     
    jaymcc, Jun 5, 2006 IP
  3. vectorgraphx

    vectorgraphx Guest

    Messages:
    545
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #3
    looks like you might not be fully escaping your sql statement to include your "inventory" variable.

    instead of

    sql_check = "select email from newsletter where email =' & inventory & '"

    try

    sql_check = "select email from newsletter where email ='" & inventory & "'"

    note the additional double quotes separating the apostropes and the ampersands.

    hth :D

    VG
     
    vectorgraphx, Jun 5, 2006 IP