#1
  1. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jan 2013
    Location
    Roanoke, VA
    Posts
    23
    Rep Power
    0

    checking for duplicates from form input, cannot insert data


    What am I doing wrong here? I am trying to check for duplicate users. If duplicate, then "User already exists" If not a duplicate, insert the data in the database.

    It seems to work EXCEPT if it is not a duplicate, the data is not being inserted into the database. Thanks for your help!


    Code:
    <% u_user=request.form("username2")
       u_password=request.form("password2")
       u_rdate=request.form("rdate")
     %>
    
    
    <%
    u_user = Replace(u_user, "'", "''")
    u_password = Replace(u_password, "'", "''")
    %>
    
    
    <%
    
    accessdb = "secure"
    'Err.Clear
    'On Error Resume Next
    cn="DRIVER={Microsoft Access Driver (*.mdb)};"
    cn=cn & "DBQ=" & server.mappath(accessdb) & ";PWD=XXXX"
    
    set rs = server.createobject("ADODB.Recordset")
    
    sql= "SELECT * FROM login WHERE '" + u_user + "' = user" 
    
    rs.Open sql, cn
    
    %>
    
    
    <%
    On Error Resume Next
    rs.MoveFirst
    if(rs.eof) Then
    
    SQL = "insert into login (user, password, rdate)"
    SQL = SQL & "values ('" & u_user
    SQL = SQL & "','" & u_password
    SQL = SQL & "','" & u_rdate & "')"
    
    Response.Write("<b>You have been registered!</b>")
    
    else
    	Response.Write("<b>User already exists!</b>")
      	
    End If
    do while Not rs.eof  
    %>
    
    
    <%
    rs.MoveNext
    loop
    %>
    
    
    <%
    rs.close
    conn.close
    set rs = Nothing
    set conn = Nothing
    %>
  2. #2
  3. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jan 2013
    Location
    Roanoke, VA
    Posts
    23
    Rep Power
    0

    Resolved!


    Code:
    <% 
       u_repuser=request.form("username2")
       u_reppassword=request.form("password2")
       u_rdate=request.form("rdate")
       u_admin=request.form("admin")
    %>
    
    
    
    <%
    u_repuser = Replace(u_repuser, "'", "''")
    u_reppassword = Replace(u_reppassword, "'", "''")
    
    %>
    
    
    <%
    database=("secure.mdb")
    %>
    
    <%
    set conn=Server.CreateObject("ADODB.Connection")
    conn.Provider="Microsoft.Jet.OLEDB.4.0"
    conn.Open(Server.Mappath(database))
    set rs=Server.CreateObject("ADODB.Recordset")
    rs.open "SELECT * FROM login WHERE '" + u_repuser + "' = repuser" , conn
    
    On Error Resume Next
    rs.MoveFirst
    
    If(rs.eof) Then
       
      SQL = "insert into login (repuser, reppassword, admin, rdate)"
      SQL = SQL & "values ('" & u_repuser
      SQL = SQL & "','" & u_reppassword
      SQL = SQL & "','" & u_admin
      SQL = SQL & "','" & u_rdate & "')"
    
       conn.Execute sql
    
      response.write("You have been registered!")
    
    else
    response.write("User already exists!")
    
    End If
    do while Not rs.eof  
    %>
    
    
    
    
    <%
    rs.MoveNext
    loop
    %>
    
    
    
    <%
    rssecure.Close
    SET rssecure = Nothing
    conn.close
    SET conn = Nothing
    %>

Similar Threads

  1. Checking DB content against form data
    By joestmc in forum Visual Basic Programming
    Replies: 1
    Last Post: October 28th, 2008, 04:40 PM
  2. Checking database for duplicates before to update
    By maij in forum .NET Development
    Replies: 0
    Last Post: September 12th, 2008, 04:39 AM
  3. Checking for specific data in a submitted form.
    By f4llen in forum ASP Development
    Replies: 2
    Last Post: April 9th, 2008, 12:05 PM
  4. Checking for duplicates (whats wrong!)
    By badprogrammer in forum ASP Development
    Replies: 2
    Last Post: February 10th, 2005, 09:35 AM
  5. Checking for duplicates in table
    By kofseattle in forum ASP Development
    Replies: 3
    Last Post: May 11th, 2004, 02:21 PM

IMN logo majestic logo threadwatch logo seochat tools logo