[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

add records to an access database using asp

Posted on 2004-11-13
38
Medium Priority
?
232 Views
Last Modified: 2008-02-01
Hi experts,
   I'm trying to add records to an access database using asp. Please see my code below that I'm using. Its not working. I ;m having an error at line 39  which is "conn.execute(ins)". I'm trying what I know , but its not solving the problem. Please tell me what to do.

My code are
<html>
<link rel="stylesheet" type="text/css" href="../main.css">
<!--#include file="connect.asp" -->
<link rel="stylesheet" type="text/css" href="../main.css">
<body>
<%


fname=request("fname")
lname=request("lname")
address=request("address")
city=request("city")
state=request("state")
country=request("country")
phone=request("phone")
email=request("email")
p_name=request("p_name")
password1=request("password1")
flag=request("flag")



Set rsAddComments1 = Server.CreateObject("ADODB.Recordset")
sql="select count(*) from login1 where username1='"&p_name&"' "


rsAddComments1.Open sql, Conn
set rr=conn.execute(sql)
rsAddComments1.close

'if  not flag="ins" and rr(0)=0  then
'      'response.write "record found"
'      ins1 ="update customer set firstname='"&fname&"',lastname='"&lname&"',add1='"&address&"',city='"&city&"',"
'      ins1= ins1 & "state='"&state&"',country='"&country&"',phone="&phone&",email='"&email&"' where userid="&userid(0)&" "
'      conn.execute(ins1)
'      response.write(" Record must be in Data Base & Update")
'else
if flag="ins" then

      ins ="insert into login1(username1,password1) values('"&p_name&"','"&password1&"')"
      conn.execute(ins)

      sql="select userid from login1 where username1='"&p_name&"'"
      set userid=conn.execute(sql)
      'response.write userid(0)

      ins1 ="insert into customer(firstname,lastname,add1,city,state,country,phone,email,userid)"
      ins1 = ins1 & "values('"&fname&"','"&lname&"','"&address&"','"&city&"','"&state&"','"&country&"'"
      ins1 = ins1 & ","&phone&",'"&email&"',"&userid(0)&")"
else
        sql="select userid from login1 where username1='"&session("userid")&"'"
      set userid=conn.execute(sql)
        userid = session("userid")
      ins1 ="update customer set firstname='"&fname&"',lastname='"&lname&"',add1='"&address&"',city='"&city&"',"
      ins1= ins1 & "state='"&state&"',country='"&country&"',phone="&phone&",email='"&email&"' where userid="&userid&""
      

end if
'response.write ins1


conn.execute(ins1)


'end if
 
'response.end
    tt=session("psoid")
   


%>
<B> Your Data Has been saved</b><br><br><br><br><br>
<br><font face="Wingdings" color="#008000">Q  </font><a href="update_profile.asp" >Update profile</a>
<br>
<font face="Wingdings" color="#008000">Q  </font><a href="chg_pass.asp" >Change Password</a><BR>
<font face="Wingdings" color="#008000">Q  </font><a href="flight_search.asp" >reservation and cancelation</a>


<br>

</body>
</html>
0
Comment
Question by:sharfaa
  • 18
  • 14
  • 4
  • +1
38 Comments
 
LVL 9

Expert Comment

by:jmelika
ID: 12575479
What is the full error message?  Is your connection opened before you execute the SQL?  conn.Open?  You need to open it (conn.Open) and then conn.Close when done with it.

Try:
conn.Open
conn.execute(ins1)
conn.Close
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 12575481
What is Conn in your source?
Is it ConnectionString or object of type ADODB.Connection?

Look here: http:Q_10770301.html
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 12575487
I mean in this two lines it is first used as connection string and in the next line as connection object:

rsAddComments1.Open sql, Conn
set rr=conn.execute(sql)

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Expert Comment

by:jmelika
ID: 12575511
Sorry about the type in my code.  Here is the right code

conn.Open sql
conn.execute(ins1)
conn.Close
0
 

Author Comment

by:sharfaa
ID: 12575805
none of your answers have solved the problem. Please see where I have left the mistakes
0
 

Author Comment

by:sharfaa
ID: 12575824
This is the error that I have in my browser

Technical Information (for support personnel)

Error Type:
ADODB.Connection (0x800A0E79)
Operation is not allowed when the object is open.
/airline/member/input_submit.asp, line 41


0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 12575893
What is the content of:

<--#include file="connect.asp" -->


FtB
0
 

Author Comment

by:sharfaa
ID: 12575914
Hi Mr Genius,
I very happy that you are looking at my question

here is your answer of connect.asp

<html>
<body>
<%
set Conn = Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/Inetpub/wwwroot/airline/airm.mdb"
%>
</body>
</html>
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 12575933
Okay, we are going to do a little trouble shooting step by step. In a new page, try this and then tell me the result.

<html>
<link rel="stylesheet" type="text/css" href="../main.css">
<link rel="stylesheet" type="text/css" href="../main.css">
<body>
<%

set Conn = Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/Inetpub/wwwroot/airline/airm.mdb"

Response.write("The connection state is: " & Conn.state)
Response.end

fname=request("fname")
lname=request("lname")
address=request("address")
city=request("city")
state=request("state")
country=request("country")
phone=request("phone")
email=request("email")
p_name=request("p_name")
password1=request("password1")
flag=request("flag")



Set rsAddComments1 = Server.CreateObject("ADODB.Recordset")
sql="select count(*) from login1 where username1='"&p_name&"' "


rsAddComments1.Open sql, Conn
set rr=conn.execute(sql)
rsAddComments1.close

'if  not flag="ins" and rr(0)=0  then
'     'response.write "record found"
'     ins1 ="update customer set firstname='"&fname&"',lastname='"&lname&"',add1='"&address&"',city='"&city&"',"
'     ins1= ins1 & "state='"&state&"',country='"&country&"',phone="&phone&",email='"&email&"' where userid="&userid(0)&" "
'     conn.execute(ins1)
'     response.write(" Record must be in Data Base & Update")
'else
if flag="ins" then

     ins ="insert into login1(username1,password1) values('"&p_name&"','"&password1&"')"
     conn.execute(ins)

     sql="select userid from login1 where username1='"&p_name&"'"
     set userid=conn.execute(sql)
     'response.write userid(0)

     ins1 ="insert into customer(firstname,lastname,add1,city,state,country,phone,email,userid)"
     ins1 = ins1 & "values('"&fname&"','"&lname&"','"&address&"','"&city&"','"&state&"','"&country&"'"
     ins1 = ins1 & ","&phone&",'"&email&"',"&userid(0)&")"
else
        sql="select userid from login1 where username1='"&session("userid")&"'"
     set userid=conn.execute(sql)
        userid = session("userid")
     ins1 ="update customer set firstname='"&fname&"',lastname='"&lname&"',add1='"&address&"',city='"&city&"',"
     ins1= ins1 & "state='"&state&"',country='"&country&"',phone="&phone&",email='"&email&"' where userid="&userid&""
     

end if
'response.write ins1


conn.execute(ins1)


'end if
 
'response.end
    tt=session("psoid")
   


%>
<B> Your Data Has been saved</b><br><br><br><br><br>
<br><font face="Wingdings" color="#008000">Q  </font><a href="update_profile.asp" >Update profile</a>
<br>
<font face="Wingdings" color="#008000">Q  </font><a href="chg_pass.asp" >Change Password</a><BR>
<font face="Wingdings" color="#008000">Q  </font><a href="flight_search.asp" >reservation and cancelation</a>


<br>

</body>
</html>
0
 

Author Comment

by:sharfaa
ID: 12575967
The result is as follows

The connection state is: 1
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 12575977
Excellent!

Hang on a second for the next step.

FtB
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 12575982
<html>
<link rel="stylesheet" type="text/css" href="../main.css">
<link rel="stylesheet" type="text/css" href="../main.css">
<body>
<%

set Conn = Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/Inetpub/wwwroot/airline/airm.mdb"

fname=request("fname")
lname=request("lname")
address=request("address")
city=request("city")
state=request("state")
country=request("country")
phone=request("phone")
email=request("email")
p_name=request("p_name")
password1=request("password1")
flag=request("flag")



Set rsAddComments1 = Server.CreateObject("ADODB.Recordset")
sql="select count(*) from login1 where username1='"&p_name&"' "


rsAddComments1.Open sql, Conn


Response.write("The rsAddComments1 state is: " & rsAddComments1.state)
Response.end


set rr=conn.execute(sql)
rsAddComments1.close

'if  not flag="ins" and rr(0)=0  then
'     'response.write "record found"
'     ins1 ="update customer set firstname='"&fname&"',lastname='"&lname&"',add1='"&address&"',city='"&city&"',"
'     ins1= ins1 & "state='"&state&"',country='"&country&"',phone="&phone&",email='"&email&"' where userid="&userid(0)&" "
'     conn.execute(ins1)
'     response.write(" Record must be in Data Base & Update")
'else
if flag="ins" then

     ins ="insert into login1(username1,password1) values('"&p_name&"','"&password1&"')"
     conn.execute(ins)

     sql="select userid from login1 where username1='"&p_name&"'"
     set userid=conn.execute(sql)
     'response.write userid(0)

     ins1 ="insert into customer(firstname,lastname,add1,city,state,country,phone,email,userid)"
     ins1 = ins1 & "values('"&fname&"','"&lname&"','"&address&"','"&city&"','"&state&"','"&country&"'"
     ins1 = ins1 & ","&phone&",'"&email&"',"&userid(0)&")"
else
        sql="select userid from login1 where username1='"&session("userid")&"'"
     set userid=conn.execute(sql)
        userid = session("userid")
     ins1 ="update customer set firstname='"&fname&"',lastname='"&lname&"',add1='"&address&"',city='"&city&"',"
     ins1= ins1 & "state='"&state&"',country='"&country&"',phone="&phone&",email='"&email&"' where userid="&userid&""
     

end if
'response.write ins1


conn.execute(ins1)


'end if
 
'response.end
    tt=session("psoid")
   


%>
<B> Your Data Has been saved</b><br><br><br><br><br>
<br><font face="Wingdings" color="#008000">Q  </font><a href="update_profile.asp" >Update profile</a>
<br>
<font face="Wingdings" color="#008000">Q  </font><a href="chg_pass.asp" >Change Password</a><BR>
<font face="Wingdings" color="#008000">Q  </font><a href="flight_search.asp" >reservation and cancelation</a>


<br>

</body>
</html>
0
 

Author Comment

by:sharfaa
ID: 12575989
new result

The rsAddComments1 state is: 1

0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 12575994
Looking good! Hang on for a minute for the next bit.

FtB
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 12576003
<html>
<link rel="stylesheet" type="text/css" href="../main.css">
<link rel="stylesheet" type="text/css" href="../main.css">
<body>
<%

set Conn = Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/Inetpub/wwwroot/airline/airm.mdb"

fname=request("fname")
lname=request("lname")
address=request("address")
city=request("city")
state=request("state")
country=request("country")
phone=request("phone")
email=request("email")
p_name=request("p_name")
password1=request("password1")
flag=request("flag")



Set rsAddComments1 = Server.CreateObject("ADODB.Recordset")
sql="select count(*) from login1 where username1='"&p_name&"' "


rsAddComments1.Open sql, Conn


set rr=conn.execute(sql)
rsAddComments1.close

'if  not flag="ins" and rr(0)=0  then
'     'response.write "record found"
'     ins1 ="update customer set firstname='"&fname&"',lastname='"&lname&"',add1='"&address&"',city='"&city&"',"
'     ins1= ins1 & "state='"&state&"',country='"&country&"',phone="&phone&",email='"&email&"' where userid="&userid(0)&" "
'     conn.execute(ins1)
'     response.write(" Record must be in Data Base & Update")
'else
if flag="ins" then
   
     ins ="insert into login1(username1,password1) values('"&p_name&"','"&password1&"')"
     response.write("ins sql: " & ins)
       response.end

       conn.execute(ins)

     sql="select userid from login1 where username1='"&p_name&"'"
     set userid=conn.execute(sql)
     'response.write userid(0)

     ins1 ="insert into customer(firstname,lastname,add1,city,state,country,phone,email,userid)"
     ins1 = ins1 & "values('"&fname&"','"&lname&"','"&address&"','"&city&"','"&state&"','"&country&"'"
     ins1 = ins1 & ","&phone&",'"&email&"',"&userid(0)&")"
else
        sql="select userid from login1 where username1='"&session("userid")&"'"
     set userid=conn.execute(sql)
        userid = session("userid")
     ins1 ="update customer set firstname='"&fname&"',lastname='"&lname&"',add1='"&address&"',city='"&city&"',"
     ins1= ins1 & "state='"&state&"',country='"&country&"',phone="&phone&",email='"&email&"' where userid="&userid&""
     

end if
'response.write ins1


conn.execute(ins1)


'end if
 
'response.end
    tt=session("psoid")
   


%>
<B> Your Data Has been saved</b><br><br><br><br><br>
<br><font face="Wingdings" color="#008000">Q  </font><a href="update_profile.asp" >Update profile</a>
<br>
<font face="Wingdings" color="#008000">Q  </font><a href="chg_pass.asp" >Change Password</a><BR>
<font face="Wingdings" color="#008000">Q  </font><a href="flight_search.asp" >reservation and cancelation</a>


<br>

</body>
</html>
0
 

Author Comment

by:sharfaa
ID: 12576014
next result

ins sql: insert into login1(username1,password1) values('masa','pass')
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 12576026
Next:

<html>
<link rel="stylesheet" type="text/css" href="../main.css">
<link rel="stylesheet" type="text/css" href="../main.css">
<body>
<%

set Conn = Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/Inetpub/wwwroot/airline/airm.mdb"

fname=request("fname")
lname=request("lname")
address=request("address")
city=request("city")
state=request("state")
country=request("country")
phone=request("phone")
email=request("email")
p_name=request("p_name")
password1=request("password1")
flag=request("flag")



Set rsAddComments1 = Server.CreateObject("ADODB.Recordset")
sql="select count(*) from login1 where username1='"&p_name&"' "


rsAddComments1.Open sql, Conn


set rr=conn.execute(sql)
rsAddComments1.close

'if  not flag="ins" and rr(0)=0  then
'     'response.write "record found"
'     ins1 ="update customer set firstname='"&fname&"',lastname='"&lname&"',add1='"&address&"',city='"&city&"',"
'     ins1= ins1 & "state='"&state&"',country='"&country&"',phone="&phone&",email='"&email&"' where userid="&userid(0)&" "
'     conn.execute(ins1)
'     response.write(" Record must be in Data Base & Update")
'else
if flag="ins" then
   
     ins ="insert into login1(username1,password1) values('"&p_name&"','"&password1&"')"

       conn.execute(ins)
     response.write("Insert Executed!")
       response.end


     sql="select userid from login1 where username1='"&p_name&"'"
     set userid=conn.execute(sql)
     'response.write userid(0)

     ins1 ="insert into customer(firstname,lastname,add1,city,state,country,phone,email,userid)"
     ins1 = ins1 & "values('"&fname&"','"&lname&"','"&address&"','"&city&"','"&state&"','"&country&"'"
     ins1 = ins1 & ","&phone&",'"&email&"',"&userid(0)&")"
else
        sql="select userid from login1 where username1='"&session("userid")&"'"
     set userid=conn.execute(sql)
        userid = session("userid")
     ins1 ="update customer set firstname='"&fname&"',lastname='"&lname&"',add1='"&address&"',city='"&city&"',"
     ins1= ins1 & "state='"&state&"',country='"&country&"',phone="&phone&",email='"&email&"' where userid="&userid&""
     

end if
'response.write ins1


conn.execute(ins1)


'end if
 
'response.end
    tt=session("psoid")
   


%>
<B> Your Data Has been saved</b><br><br><br><br><br>
<br><font face="Wingdings" color="#008000">Q  </font><a href="update_profile.asp" >Update profile</a>
<br>
<font face="Wingdings" color="#008000">Q  </font><a href="chg_pass.asp" >Change Password</a><BR>
<font face="Wingdings" color="#008000">Q  </font><a href="flight_search.asp" >reservation and cancelation</a>


<br>

</body>
</html>
0
 

Author Comment

by:sharfaa
ID: 12576037
as seen in browser

Technical Information (for support personnel)

Error Type:
Microsoft JET Database Engine (0x80004005)
Operation must use an updateable query.
/airline/member/input_submit.asp, line 46


Browser Type:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)

Page:
POST 182 bytes to /airline/member/input_submit.asp

POST Data:
flag=ins&fname=Ashraf&lname=AUBAD&address=rouillard&city=Terre-Rouge&state=Pamplemousses&country=Mauritius&phone=5490261&email=masa@trop.com&p_name=masa&password1=pass&password2=pass

Time:
Sunday, November 14, 2004, 2:44:21 AM
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 12576039
Okay great. Please hang on a minute.

FtB
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 12576047
We are down to one of two or three problems. Please try this:

<html>
<link rel="stylesheet" type="text/css" href="../main.css">
<link rel="stylesheet" type="text/css" href="../main.css">
<body>
<%
set Conn = Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/Inetpub/wwwroot/airline/airm.mdb"

strDataPath = "c:/Inetpub/wwwroot/airline/airm.mdb"
set conn=Server.CreateObject("ADODB.Connection")
strConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;"_
                  + " Data Source= " & strDataPath & ";"_
                  + " Mode=Share Deny None;PASSWORD=;"

conn.ConnectionTimeout = 15
conn.CommandTimeout =  10
conn.Mode = 3 'adModeReadWrite
if conn.state = 0 then
      conn.Open strConnectString
end if

fname=request("fname")
lname=request("lname")
address=request("address")
city=request("city")
state=request("state")
country=request("country")
phone=request("phone")
email=request("email")
p_name=request("p_name")
password1=request("password1")
flag=request("flag")



Set rsAddComments1 = Server.CreateObject("ADODB.Recordset")
sql="select count(*) from login1 where username1='"&p_name&"' "


rsAddComments1.Open sql, Conn


set rr=conn.execute(sql)
rsAddComments1.close

'if  not flag="ins" and rr(0)=0  then
'     'response.write "record found"
'     ins1 ="update customer set firstname='"&fname&"',lastname='"&lname&"',add1='"&address&"',city='"&city&"',"
'     ins1= ins1 & "state='"&state&"',country='"&country&"',phone="&phone&",email='"&email&"' where userid="&userid(0)&" "
'     conn.execute(ins1)
'     response.write(" Record must be in Data Base & Update")
'else
if flag="ins" then
   
     ins ="insert into login1(username1,password1) values('"&p_name&"','"&password1&"')"

       conn.execute(ins)
     response.write("Insert Executed!")
       response.end


     sql="select userid from login1 where username1='"&p_name&"'"
     set userid=conn.execute(sql)
     'response.write userid(0)

     ins1 ="insert into customer(firstname,lastname,add1,city,state,country,phone,email,userid)"
     ins1 = ins1 & "values('"&fname&"','"&lname&"','"&address&"','"&city&"','"&state&"','"&country&"'"
     ins1 = ins1 & ","&phone&",'"&email&"',"&userid(0)&")"
else
        sql="select userid from login1 where username1='"&session("userid")&"'"
     set userid=conn.execute(sql)
        userid = session("userid")
     ins1 ="update customer set firstname='"&fname&"',lastname='"&lname&"',add1='"&address&"',city='"&city&"',"
     ins1= ins1 & "state='"&state&"',country='"&country&"',phone="&phone&",email='"&email&"' where userid="&userid&""
     

end if
'response.write ins1


conn.execute(ins1)


'end if
 
'response.end
    tt=session("psoid")
   


%>
<B> Your Data Has been saved</b><br><br><br><br><br>
<br><font face="Wingdings" color="#008000">Q  </font><a href="update_profile.asp" >Update profile</a>
<br>
<font face="Wingdings" color="#008000">Q  </font><a href="chg_pass.asp" >Change Password</a><BR>
<font face="Wingdings" color="#008000">Q  </font><a href="flight_search.asp" >reservation and cancelation</a>


<br>

</body>
</html>

FtB
0
 

Author Comment

by:sharfaa
ID: 12576054
Latest result
Technical Information (for support personnel)

Error Type:
Microsoft JET Database Engine (0x80004005)
Operation must use an updateable query.
/airline/member/input_submit.asp, line 58


Browser Type:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)

Page:
POST 182 bytes to /airline/member/input_submit.asp

POST Data:
flag=ins&fname=Ashraf&lname=AUBAD&address=rouillard&city=Terre-Rouge&state=Pamplemousses&country=Mauritius&phone=5490261&email=masa@trop.com&p_name=masa&password1=pass&password2=pass

Time:
Sunday, November 14, 2004, 2:51:19 AM
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 12576064
Okay, I think that I know what is going on now--it looks like you have a permissions issue. Is this your server or a hosting server? What we need is for the IUSR_ account to have READ/WRITE permissions for the airline/ directory. Also, right click on the .mdb file to make certain that it is not read only.

FtB

0
 

Author Comment

by:sharfaa
ID: 12576088
I'm using my own machine as server-Simulating with IIS
0
 

Author Comment

by:sharfaa
ID: 12576097
Have check permission on mdb-Its not read only
0
 

Author Comment

by:sharfaa
ID: 12576103
can I upload my pages somewhere-so that you have a better idea of the problem
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 12576104
Okay, so visit the airline directory, right click on it to check the permissions. The IUSR_ account must have READ/WRITE permissions.

FtB
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 12576108
That won't help--what I need is to see your server. In any event, please see my last comment about the IUSR permissions.

FtB
0
 

Author Comment

by:sharfaa
ID: 12576124
Now i have this comments after checking the permissions with IIS server

Insert Executed!
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 12576133
Excellent. Can you verify that the record was inserted?

ftB
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 12576141
If so, then your code should look like this to go all of the way through:

<html>
<link rel="stylesheet" type="text/css" href="../main.css">
<link rel="stylesheet" type="text/css" href="../main.css">
<body>
<%
set Conn = Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/Inetpub/wwwroot/airline/airm.mdb"

strDataPath = "c:/Inetpub/wwwroot/airline/airm.mdb"
set conn=Server.CreateObject("ADODB.Connection")
strConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;"_
                  + " Data Source= " & strDataPath & ";"_
                  + " Mode=Share Deny None;PASSWORD=;"

conn.ConnectionTimeout = 15
conn.CommandTimeout =  10
conn.Mode = 3 'adModeReadWrite
if conn.state = 0 then
      conn.Open strConnectString
end if

fname=request("fname")
lname=request("lname")
address=request("address")
city=request("city")
state=request("state")
country=request("country")
phone=request("phone")
email=request("email")
p_name=request("p_name")
password1=request("password1")
flag=request("flag")



Set rsAddComments1 = Server.CreateObject("ADODB.Recordset")
sql="select count(*) from login1 where username1='"&p_name&"' "


rsAddComments1.Open sql, Conn


set rr=conn.execute(sql)
rsAddComments1.close

'if  not flag="ins" and rr(0)=0  then
'     'response.write "record found"
'     ins1 ="update customer set firstname='"&fname&"',lastname='"&lname&"',add1='"&address&"',city='"&city&"',"
'     ins1= ins1 & "state='"&state&"',country='"&country&"',phone="&phone&",email='"&email&"' where userid="&userid(0)&" "
'     conn.execute(ins1)
'     response.write(" Record must be in Data Base & Update")
'else
if flag="ins" then
   
     ins ="insert into login1(username1,password1) values('"&p_name&"','"&password1&"')"
       conn.execute(ins)

     sql="select userid from login1 where username1='"&p_name&"'"
     set userid=conn.execute(sql)
     'response.write userid(0)

     ins1 ="insert into customer(firstname,lastname,add1,city,state,country,phone,email,userid)"
     ins1 = ins1 & "values('"&fname&"','"&lname&"','"&address&"','"&city&"','"&state&"','"&country&"'"
     ins1 = ins1 & ","&phone&",'"&email&"',"&userid(0)&")"
else
        sql="select userid from login1 where username1='"&session("userid")&"'"
     set userid=conn.execute(sql)
        userid = session("userid")
     ins1 ="update customer set firstname='"&fname&"',lastname='"&lname&"',add1='"&address&"',city='"&city&"',"
     ins1= ins1 & "state='"&state&"',country='"&country&"',phone="&phone&",email='"&email&"' where userid="&userid&""
     

end if
'response.write ins1
conn.execute(ins1)
'end if

'response.end
    tt=session("psoid")
 %>
<B> Your Data Has been saved</b><br><br><br><br><br>
<br><font face="Wingdings" color="#008000">Q  </font><a href="update_profile.asp" >Update profile</a>
<br>
<font face="Wingdings" color="#008000">Q  </font><a href="chg_pass.asp" >Change Password</a><BR>
<font face="Wingdings" color="#008000">Q  </font><a href="flight_search.asp" >reservation and cancelation</a>
</body>
</html>

FtB
0
 

Author Comment

by:sharfaa
ID: 12576144
Yes the record was inserted in the login table
0
 
LVL 46

Accepted Solution

by:
fritz_the_blank earned 2000 total points
ID: 12576156
Okay, then the code above should be fine. I would recommend copying and pasting my connection code into your include file and then putting the include statement back into your page. Also, be sure to put:

conn.close
set conn = Nothing


at the bottom of your page. Do the same with each recordset you create.

ftB
0
 

Author Comment

by:sharfaa
ID: 12576195
Thanks a lot for your effort-Now I know where the problem was-It has to do with permissions as you have said
You are really a genius in ASP

thanks
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 12576212
Glad to have helped,

FtB

PS: Some good folks were helping you out earlier as well.

0
 
LVL 63

Expert Comment

by:Zvonko
ID: 12576233
Come on Fritz, I would never guessed that the problem was access rights ;-)
I was only wondering why he executes the sql string twice!

rsAddComments1.Open sql, Conn

set rr=conn.execute(sql) '// << isn't this a problem before close() ???

rsAddComments1.close
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 12576453
I don't think so--you just get another recordset.

FtB
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 12576461
Ok, thanks.
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 12576480
But please don't quote me on that!!!! I prefer to do things more explicitly so that I can set the properties of the objects myself. i.e.:

dim rr
set rr = server.CreateObject("ADODB.RecordSet")
rr.Open strSQL,conn,3,3




0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question