Print Page | Close Window

desp. updating record prob

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=764
Printed Date: 29 March 2026 at 10:53am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: desp. updating record prob
Posted By: funki
Subject: desp. updating record prob
Date Posted: 06 March 2003 at 1:08am

I am working on a access Db where I read records from the databse back into a form to update and then resend back to the dbase using update.  I ahve written the following code. Alll that happens is the page does not display.I hoping to seacrh the records set where userId is my link to each record the code is as follows:_

Session("fname") = request("fname")
Session("sname") = Request("sname")
Session("uname") = Request("uname")
Session("pswd") = Request("pswd")
Session("addra") = Request("addra")
Session("addrb") = Request("addrb")
session("county") = Request("county")
Session("postcode") = Request("postcode")
Session("telno") = Request("telno")
Session("fax") = Request("fax")
Session("email") = Request("email")

else


Set MyConn = Server.CreateObject("ADODB.Connection")
MyConn.Open = "DRIVER={Microsoft Access Driver (*.mdb)};" & _
    "DBQ=" & Server.MapPath("db2.mdb") & ";"

sql1 = "Update users Set fname='" & fname & "', sname='" & sname & "' , uname='" & uname & "', pswd='" & pswd & "', addra='" & addra & "', addrb='" & addrb & "', county='" & county & "', postcode='" & postcode & "', telno='" & telno & "', fax='" & fax & "', email='" & email & "', act='" & act & "' Where userID='" & userID& "'"

MyConn.Execute(sql1)

Conn.close
%>

Can some please help me as I am facing a major deadline I have tied several version of updating and none of them seem to work. Hears hoping, any way peace to you all.




Replies:
Posted By: Gary
Date Posted: 06 March 2003 at 4:40am

It looks like the values are not being placed in SQL string.
Depending on the form's method (post/get) you should do the following (dont worry about the session stuff).....

Method="Post"
sql1 = "Update users Set fname='" & request.form("fname") & "', sname='" & request.form("sname") and so on......

Method="Get"
sql1 = "Update users Set fname='" & request.querystring("fname") & "', sname='" & request.querystring("sname") and so on......



Posted By: MorningZ
Date Posted: 06 March 2003 at 8:30am
"Request" is generic, it'll pic up either posted data or data on the URL line

but they poster says "page doesn't show"

i dont see any code that shows anything.. that would be one issue...

if there's an error, he doesn't let us know what the error is...

if there is something wrong with the SQL query built, then i bet he didn't Response.Write out the string right before it gets executed to see if the quewry was in fact, correct

-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: funki
Date Posted: 06 March 2003 at 10:21am

                    <%

'Collating all the information from the form using the the request command.

fname = TRIM(request("fname"))
sname = TRIM(request("sname"))
uname = TRIM(request("uname"))
pswd = TRIM(request("pswd"))
addra = TRIM(Request("addra"))
addrb = TRIM(Request("addrb"))
county = TRIM(Request("county"))
postcode = TRIM(Request("postcode"))
telno = TRIM(Request("telno"))
fax = TRIM(Request("fax"))
email=Trim(Request("email"))

 

'Error checking of the element thatg make up the form

if fname = "" then

 strError = strError & "Enter your first name.<BR>"
 
end if
if sname = "" then

 strError = strError & "Enter your surname.<BR>"
 
end if
if uname = "" then

 strError = strError & "Enter a user name.<BR>"
 
end if
if pswd = "" then

 strError = strError & "Enter a password .<BR>"
 
end if


if addra = "" then

 strError = strError & "Enter in your address line 1.<BR>"
end if

if addrb = "" then

 strError = strError & "Enter  in your address line 2.<BR>"
end if


if county = "" then

 strError = strError & "Enter  in your City or County.<BR>"
end if

if  postcode="" then
 strError = strError & "Enter your Postcode <BR>"

end if

if telno = "" then

 strError = strError & "Enter  your Telephone<BR>"

end if

if email="" then
strError = strError & " Enter your email<br>"
else
if (instr(1, email,"@")=0) or (instr(1, email, ".")=0) then
strError = strError & " Invalid email<br>"
end if
end if

 

' if there are any error they will be picked up by this next term

if strError <> "" then

%>
                    <!-- Note the error -->
                    <b> There is an error in your registration request: </b> </span>
                  <p> <span class="error">
                    <%

 '  Write out the error messages
 Response.Write strError

%>
                    </span> <br>
                    Click <a href="userupdate.asp" class="purp">here</a>
                    to update.
                    <%

 ' If there are any probelms with form the  information is placed into sessionvariable
 ' for when you are sent back to last page.
 
Session("fname") = request("fname")
Session("sname") = Request("sname")
Session("uname") = Request("uname")
Session("pswd") = Request("pswd")
Session("addra") = Request("addra")
Session("addrb") = Request("addrb")
session("county") = Request("county")
Session("postcode") = Request("postcode")
Session("telno") = Request("telno")
Session("fax") = Request("fax")
Session("email") = Request("email")

else

Session("fname") = request("fname")
Session("sname") = Request("sname")
Session("uname") = Request("uname")
Session("pswd") = Request("pswd")
Session("addra") = Request("addra")
Session("addrb") = Request("addrb")
session("county") = Request("county")
Session("postcode") = Request("postcode")
Session("telno") = Request("telno")
Session("fax") = Request("fax")
Session("email") = Request("email")

else


Set MyConn = Server.CreateObject("ADODB.Connection")
MyConn.Open = "DRIVER={Microsoft Access Driver (*.mdb)};" & _
    "DBQ=" & Server.MapPath("db2.mdb") & ";"

sql1 = "Update users Set fname='" & fname & "', sname='" & sname & "' , uname='" & uname & "', pswd='" & pswd & "', addra='" & addra & "', addrb='" & addrb & "', county='" & county & "', postcode='" & postcode & "', telno='" & telno & "', fax='" & fax & "', email='" & email & "', act='" & act & "' Where userID='" & userID& "'"

MyConn.Execute(sql1)

Conn.close
%>

Here is my sode that is inserted int0 HTML page under neath values are displayed in table,

this is what is displayed on my page instead of table I dont understand where I ahve gone wrong as I can insert and read from same table using same recordset why is now being treated differently

Microsoft OLE DB Provider for ODBC Drivers error '80040e07'

[Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.

/userupdateverification.asp, line 340

Thanks for any help offered. Peace



Posted By: Gary
Date Posted: 06 March 2003 at 10:38am

It could be the WHERE clause in the SQL.....

What datatype is UserID? If it is integer then lose the single quotes...


& "' Where userID=" & userID



Posted By: funki
Date Posted: 06 March 2003 at 10:55am

Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC Microsoft Access Driver] Syntax error in UPDATE statement.

/userupdateverification.asp, line 340

 

is whgat appears when I take quotes out of code listed above.

When I change the code  & lose single quotes in the version where I use response.form as per you suggestion but when i dothis oages does not appear at all.

eg.

Set MyConn = Server.CreateObject("ADODB.Connection")
MyConn.Open = "DRIVER={Microsoft Access Driver (*.mdb)};" & _
    "DBQ=" & Server.MapPath("db2.mdb") & ";"

sql1 = "Update users Set fname='" & request.form("fname") & "', sname='" & request.form("sname") & "' , uname='" & request.form("uname") & "', pswd='" & request.form("pswd") & "', addra='" & request.form("addra") & "', addrb='" & request.form("addrb") & "', county='" & request.form("county ")& "', postcode='" & request.form("postcode") & "', telno='" & request.form("telno") & "', fax='" & request.form("fax") & "', email='" & request.form("email") & "', act=" & request.form("act") & " Where userID=" & request.form("userID")& ""

MyConn.Execute(sql1)

I'll keep on trying as I have got to getover this hurdle if it kills me.



Posted By: MorningZ
Date Posted: 06 March 2003 at 10:59am
instead of guessing, whjy dont you do as suggested above

sql1 = "Update users Set fname='" & request.form("fname") & "', sname='" & request.form("sname") & "' , uname='" & request.form("uname") & "', pswd='" & request.form("pswd") & "', addra='" & request.form("addra") & "', addrb='" & request.form("addrb") & "', county='" & request.form("county ")& "', postcode='" & request.form("postcode") & "', telno='" & request.form("telno") & "', fax='" & request.form("fax") & "', email='" & request.form("email") & "', act=" & request.form("act") & " Where userID=" & request.form("userID")& ""

Response.Write(sql1)
Response.End


MyConn.Execute(sql1)


-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: Gary
Date Posted: 06 March 2003 at 11:02am

As per MorningZ post, i would strongly recommend that you response.write the sql and then .end it

Also, if you could post the table structure (column names & datatypes) it would be helpful.



Posted By: funki
Date Posted: 06 March 2003 at 11:13am

 

Okay hers goes

result first from response.write

looks like act and userID which are the only two numbers in record set are not being populated. everythig else is loaded. So Morning Z & gary thanks for helping  me to open my eyes will look at variable passing from previous pages. Will respond if succesfull or not.

PS thanks again at least I not hitting my head against the wall so hard.



Posted By: funki
Date Posted: 06 March 2003 at 11:32am

Here is how I populate variables from previous form page.

userID=session("userID")
fname = TRIM(request("fname"))
sname = TRIM(request("sname"))
uname = TRIM(request("uname"))
pswd = TRIM(request("pswd"))
addra = TRIM(Request("addra"))
addrb = TRIM(Request("addrb"))
county = TRIM(Request("county"))
postcode = TRIM(Request("postcode"))
telno = TRIM(Request("telno"))
fax = TRIM(Request("fax"))
email=Trim(Request("email"))
act=0

Below the First number is printed using <%=userID%> so the value is there but not when it comes to being included in SQL. IN additon as you can see from above I also hard code act number into page but this also does not show  any suggestions guys . What am I doing wrong.

2 --- Update users Set fname='tom', sname='jones' , uname='jones', pswd='tom', addra='Docks', addrb='Docks', county='', postcode='CF1', telno='0292 678678', fax='xxxx', mailto:email='jfvkjsdhf@.' - email='jfvkjsdhf@.' , act= Where userID=



Posted By: Gary
Date Posted: 06 March 2003 at 11:45am

1. Are you sure that the UserID session variable is being set ?

2. Please post the entire code again



Posted By: funki
Date Posted: 06 March 2003 at 12:00pm

          Here is all the code for this page - to give you brief login using uname and pswd, - passed to userwelcome page which queries for userID which is then stored as session  passedonto profile diplay page where userID is taken from session and passed on as hdden field in form. UserID appears on final page the one listed below as you will not from my last message - hope I have not confused situation  .   

<%

'Collating all the information from the form using the the request command.

 

userID=session("userID")
fname = TRIM(request("fname"))
sname = TRIM(request("sname"))
uname = TRIM(request("uname"))
pswd = TRIM(request("pswd"))
addra = TRIM(Request("addra"))
addrb = TRIM(Request("addrb"))
county = TRIM(Request("county"))
postcode = TRIM(Request("postcode"))
telno = TRIM(Request("telno"))
fax = TRIM(Request("fax"))
email=Trim(Request("email"))

act=0


'Error checking of the element that make up the form

if fname = "" then

 strError = strError & "Enter your first name.<BR>"
 
end if
if sname = "" then

 strError = strError & "Enter your surname.<BR>"
 
end if
if uname = "" then

 strError = strError & "Enter a user name.<BR>"
 
end if
if pswd = "" then

 strError = strError & "Enter a password .<BR>"
 
end if


if addra = "" then

 strError = strError & "Enter in your address line 1.<BR>"
end if

if addrb = "" then

 strError = strError & "Enter  in your address line 2.<BR>"
end if


if county = "" then

 strError = strError & "Enter  in your City or County.<BR>"
end if

if  postcode="" then
 strError = strError & "Enter your Postcode <BR>"

end if

if telno = "" then

 strError = strError & "Enter  your Telephone<BR>"

end if

if email="" then
strError = strError & " Enter your email<br>"
else
if (instr(1, email,"@")=0) or (instr(1, email, ".")=0) then
strError = strError & " Invalid email<br>"
end if
end if

 

' if there are any error they will be picked up by this next term

if strError <> "" then

%>
                    <!-- Note the error -->
                    <b> There is an error in your registration request: </b> </span>
                  <p> <span class="error">
                    <%

 '  Write out the error messages
 Response.Write strError

%>
                    </span> <br>
                    Click <a href="userupdate.asp" class="purp">here</a>
                    to update.
                    <%

 ' If there are any probelms with form the  information is placed into sessionvariable
 ' for when you are sent back to last page.
 
Session("fname") = request("fname")
Session("sname") = Request("sname")
Session("uname") = Request("uname")
Session("pswd") = Request("pswd")
Session("addra") = Request("addra")
Session("addrb") = Request("addrb")
session("county") = Request("county")
Session("postcode") = Request("postcode")
Session("telno") = Request("telno")
Session("fax") = Request("fax")
Session("email") = Request("email")

else
%>
<font>   <% = userID %></font>
<%

Set MyConn = Server.CreateObject("ADODB.Connection")
MyConn.Open = "DRIVER={Microsoft Access Driver (*.mdb)};" & _
    "DBQ=" & Server.MapPath("db2.mdb") & ";"
 
sql1 = "Update users Set fname='" & request.form("fname") & "', sname='" & request.form("sname") & "' , uname='" & request.form("uname") & "', pswd='" & request.form("pswd") & "', addra='" & request.form("addra") & "', addrb='" & request.form("addrb") & "', county='" & request.form("county ")& "', postcode='" & request.form("postcode") & "', telno='" & request.form("telno") & "', fax='" & request.form("fax") & "', email='" & request.form("email") & "', act=" & request.form("act") & " Where userID=" & request.form("userID")& ""

Response.Write(sql1)
Response.End

MyConn.Execute(sql1)
%>



Posted By: Gary
Date Posted: 06 March 2003 at 12:11pm

Revised sql statement.....

sql1 = "Update users Set fname='" & request.form("fname") & "', sname='" & request.form("sname") & "' , uname='" & request.form("uname") & "', pswd='" & request.form("pswd") & "', addra='" & request.form("addra") & "', addrb='" & request.form("addrb") & "', county='" & request.form("county ")& "', postcode='" & request.form("postcode") & "', telno='" & request.form("telno") & "', fax='" & request.form("fax") & "', email='" & request.form("email") & "', act=" & act & " Where userID=" & UserID

Notice that I changed the 'act' and 'userid' parts towards the end.




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net