Problem in connection

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • deepaks85
    New Member
    • Aug 2006
    • 114

    Problem in connection

    Dear Friends,

    I have designed an MIS modulue but I am facing some problem. The form is not able to connect with the server and I also can not submit my details to the database. Here is the code:


    connection.asp

    Code:
    <!-- #include file="../adovbs.inc" -->
    
    <% Dim aConnectionString
    aConnectionString = "Provider=SQLOLEDB;Data Source=afcindia;Initial Catalog= afcindia;UserId=afcindia;Password=afc789;"
    
    Dim conn,R,SQL,RecsAffected
    
    Set conn=Server.CreateObject("ADODB.Connection")
    conn.Mode=adModeReadWrite
    conn.ConnectionString = aConnectionString
    conn.Open
    
    %>
    validatelogin.a sp (This will check whether user exists or not)

    Code:
    <!-- #include file="include/connection.asp" -->
    <%
    
    dim username,password
    dim query
    	username=request("username")
    	password=request("password")
    	Ltype=request("Ltype")
    	
    	query="select * from Login where UserName ='" & username & "' and Password='" & password & "'
    	set rs=server.CreateObject("adodb.recordset")
    	rs.open query,con,1,3
    	if rs.eof and rs.bof then
    	response.Redirect("default.asp?vartext=Invalid Login !,Try Again.")
    	else
    	session("username")=username
    	session("type")="Admin"
    	session("branch")=rs("branch")
    	response.Redirect("newmenu.asp")
    
    	end if
    	
    	
    
    	%>
    function_login. asp (This will submit the information of user)

    Code:
    <!-- #include file="include/connection.asp" -->
    <% 
    
    uname=request("userid")
    pass=request("pass")
    branch=request("branch")
    query1="Select UserName from Login where UserName='"& uname &"'"
    set rs1=Server.CreateObject("adodb.recordset")
    rs1.Open query1,con,1,3
    
    if  rs1.eof and  rs1.bof then 
     
    query="insert into Login (UserName,Password,Branch,Status)values('"& uname &"','"& pass &"', '" "',1)"
    set rs2=Server.CreateObject("adodb.recordset")
    rs2.Open query,con,1,3
    response.Redirect("NewLogin.asp?action=done")
    else
    response.Redirect("NewLogin.asp?action=Exist")
    end if 
    %>



    Please advice me where is the problem.


    Thanks
    Deepak
    Last edited by jhardman; Apr 14 '07, 06:22 AM. Reason: place codes in code tags
  • Arnold Schuur
    New Member
    • Apr 2007
    • 36

    #2
    You declared a connection object with a name "conn" in connection.asp but you refer to it as "con" (single n) in function_login. asp

    If you want to insert a record, you should make use of the connection object which was opened in connection.asp and use the execute method.

    Code:
    Code:
    query="insert into Login (UserName,Password,Branch,Status)values('"& uname &"','"& pass &"', '" "',1)"
    conn.execute query
    conn.close

    Comment

    Working...