Solved

editing database records

Posted on 2003-11-18
28
436 Views
Last Modified: 2008-02-01
Can someone please tell me what is wrong with this code.  I have worked on it all day.  I have retrieved a record from the database on anotherpage, passing the data from that record to text boxes in this page, and then need to edit the data and put back in the database.

It gives me a error of:
Error Type:
Microsoft VBScript runtime (0x800A01BE)
Object doesn't support named arguments: 'commandtype'
/dcphilli/Lab5/editstudent.asp, line 92


but the const adcmdtext is defined in the adovbs file that is in an include statement in the db.asp file



<!-- #include file = "db.asp" -->
<%


'File Name: editstudent.asp
'Purpose:  To edit student record found in findstudent.asp


dim strcriteria
dim rsedit
set rsedit = server.createobject ("ADODB.recordset")
'rsedit.open "student", objconn, adopenstatic, adlockpessimistic, adcmdtable

strssn = request.form("SSN")
If request.querystring("end") = 1 then
      session.Abandon
end if


strssn = session("SSN")

'select statement to find data in database
strsql = "select ssn, firstname, lastname,  NickName, emailadd, phone, picturefile  from student where ssn =  '" &  strssn & "'"


'Set the cursor type
rsedit.cursortype = 2

'open table
rsedit.open strsql, objconn

'Populate Recordset with Data
      set rsedit = objconn.execute (strsql)
      

%>





<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Edit Student</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>





<br>
<br>
<%
'assign values to session variables

      fname = session("firstName")
      lname = session("lastName")
      nname = session("NickName")
      email = session("eMailAdd")
      phonenum = session("Phone")
      

%>
<h1><p align="center"><span class="style3"><FONT COLOR="#8fbc8f">Edit Student Record For<br>
<%response.write strssn%></FONT> </span><BR></h1>

      <b> <font face="Arial, Helvetica, sans-serif">First Name:</font> </b>
      <input type = text name = "firstname" size = "26" value = "<%= session("firstname") %> "><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <b> <font face="Arial, Helvetica, sans-serif">Last Name:</font> </b>
    <input type = text  name = "lastname" size = "26" value = "<%= session("lastname") %>"><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face="Arial, Helvetica, sans-serif">
    <b>Nick Name:</b>
</font>
    <input type = text name = "NickName" size = "26" value = "<%= session("NickName") %>"><br>
    <b><font face="Arial, Helvetica, sans-serif">E-Mail Address:</font></b>
    <input type = text name = "emailadd" size = "26" value = "<%= session("EMailAdd") %>"><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<font face="Arial, Helvetica, sans-serif">
      <b>Phone:</b>
</font>
    <input type = text name = "Phone" size = "26" value = "<%= session("Phone") %>"><br>
      
<br>
<br>
<%'update the record in the recordset
objconn.commandtype=adcmdtext
editsql = "UPDATE student SET firstname = fname, lastname = lname, nickname = nname, emailadd = email, phone = phonenum where ssn = '" &  strssn & "'"
rsedit.commandtext = editsql



%>
      <form action = "editstudent.asp" method = post>
      <input type = "submit" name = "edit" value = "Submit Changes">
<br>

<br>
<br>
<a href="http://baeacd.uncg.edu/dcphilli/lab5/default.asp" title="Return" target="_parent">Return to Search Page</a>

</form>
<%
'write the updated recordset to the database
rsedit.update

'close recordset and connection
rsedit.close
set rsedit = nothing
set objconn = nothing
%>

    </body>
</html>



0
Comment
Question by:dcphilli
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 15
  • 13
28 Comments
 
LVL 19

Expert Comment

by:Dexstar
ID: 9775242
dcphilli:

> <%'update the record in the recordset
> objconn.commandtype=adcmdtext
> editsql = "UPDATE student SET firstname = fname, lastname = lname, nickname
> = nname, emailadd = email, phone = phonenum where ssn = '" &  strssn & "'"
> rsedit.commandtext = editsql
> %>

Your problem is here.  RSEdit is a Recordset Object, but you're trying to use it as a Command object.  (CommandType is a property of the Command object).

Change the above code to be like this:
<%
   Dim objCmd

   Set objCmd = Server.CreateObject("ADODB.Command")
   objCmd.ActiveConnection = objconn
   objCmd.CommandType = adCmdText
   objCmd.CommandText = editsql

   objCmd.Execute
%>

That will fix the immediate problem mentioned in your question...

Hope That Helps,
Dex*
0
 

Author Comment

by:dcphilli
ID: 9775326
changed to:
<%'update the record in the recordset
dim objcmd
set objcmd = server.createobject("ADODB.command")
objcmd.activeconnection = objconn
objcmd.commandtype = adcmdtext
editsql = "UPDATE student SET firstname = fname, lastname = lname, nickname = nname, emailadd = email, phone = phonenum where ssn = '" &  strssn & "'"
objcmd.commandtext = editsql
objcmd.execute

%>

Now getting error of:
Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E10)
[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 5.
/dcphilli/lab5/editstudent.asp, line 98

which is the line of
objcmd.execute
0
 
LVL 19

Expert Comment

by:Dexstar
ID: 9775362
Change this line:
editsql = "UPDATE student SET firstname = fname, lastname = lname, nickname = nname, emailadd = email, phone = phonenum where ssn = '" &  strssn & "'"

To this:
editsql = "UPDATE student SET firstname = '" & fname & "', lastname = '" & lname & "', nickname = '" & nname & "', emailadd = '" & email & "', phone = '" & phonenum & "' where ssn = '" &  strssn & "'"

Enjoy,
Dex*

0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:dcphilli
ID: 9775398
thanks, but now it doesn't give any errors, but it doesn't change the database when I change a value in the text boxes.

Any more suggestions?

thanks
Denise
0
 
LVL 19

Expert Comment

by:Dexstar
ID: 9775416
Before that line put this:

    fname = Request.Form("firstName")
    lname = Request.Form("lastName")
    nname = Request.Form("NickName")
    email = Request.Form("eMailAdd")
    phonenum = Request.Form("Phone")
0
 

Author Comment

by:dcphilli
ID: 9775458
okay, now I have:

<%'update the record in the recordset
dim objcmd
set objcmd = server.createobject("ADODB.command")
objcmd.activeconnection = objconn
objcmd.commandtype = adcmdtext

      fname = Request.Form("firstName")
    lname = Request.Form("lastName")
    nname = Request.Form("NickName")
    email = Request.Form("eMailAdd")
    phonenum = Request.Form("Phone")

editsql = "UPDATE student SET firstname = '" & fname & "', lastname = '" & lname & "', nickname = '" & nname & "', emailadd = '" & email & "', phone = '" & phonenum & "' where ssn = '" &  strssn & "'"
objcmd.commandtext = editsql
objcmd.execute



%>
      <form action = "editstudent.asp" method = post>
      <input type = "submit" name = "edit" value = "Submit Changes">
<br>



and I'm getting an error of:

Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80004005)
[Microsoft][ODBC Microsoft Access Driver] Field 'student.FirstName' cannot be a zero-length string.
/dcphilli/lab5/editstudent.asp, line 109


on the line
objcmd.execute

Did I put the request statements in the wrong place?


0
 
LVL 19

Expert Comment

by:Dexstar
ID: 9775586
No, you put it in the right spot, but your executing the update code when there is no update to make yet.

Do these 2 things:

1) Wrap that whole "update" block in an If/Then statement

<%
     dim objcmd

     If Request.Form("edit") <> "" Then
          set objcmd = server.createobject("ADODB.command")
          objcmd.activeconnection = objconn
          objcmd.commandtype = adcmdtext

          fname = Request.Form("firstName")
          lname = Request.Form("lastName")
          nname = Request.Form("NickName")
          email = Request.Form("eMailAdd")
          phonenum = Request.Form("Phone")

          editsql = "UPDATE student SET firstname = '" & fname & "', lastname = '" & lname & "', nickname = '" & nname & "', emailadd = '" & email & "', phone = '" & phonenum & "' where ssn = '" &  strssn & "'"
          objcmd.commandtext = editsql
          objcmd.execute
End If
%>

2) Put all your form code together, like this:
<h1><p align="center"><span class="style3"><FONT COLOR="#8fbc8f">Edit Student Record For<br>
<%response.write strssn%></FONT> </span><BR></h1>
     <form action = "editstudent.asp" method = post>
          <input type = "submit" name = "edit" value = "Submit Changes">
          <b> <font face="Arial, Helvetica, sans-serif">First Name:</font> </b>
          <input type = text name = "firstname" size = "26" value = "<%= session("firstname") %> "><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          <b> <font face="Arial, Helvetica, sans-serif">Last Name:</font> </b>
          <input type = text  name = "lastname" size = "26" value = "<%= session("lastname") %>"><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face="Arial, Helvetica, sans-serif">
          <b>Nick Name:</b>
</font>
          <input type = text name = "NickName" size = "26" value = "<%= session("NickName") %>"><br>
          <b><font face="Arial, Helvetica, sans-serif">E-Mail Address:</font></b>
          <input type = text name = "emailadd" size = "26" value = "<%= session("EMailAdd") %>"><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<font face="Arial, Helvetica, sans-serif">
          <b>Phone:</b>
     </font>
     <input type = text name = "Phone" size = "26" value = "<%= session("Phone") %>"><br>
</form>
0
 

Author Comment

by:dcphilli
ID: 9775708
Okay, I made it like yours, but when I change the information in the text boxes and click submit, the original information comes back to the text box and no update has occured in the database.
0
 

Author Comment

by:dcphilli
ID: 9780635
This is the code I have now.  However, when the record appears in the text boxes and one of the fields is changed, when submit is clicked, the original entry in the field shows back on the screen and no update happens in the database.

What am I doing wrong?

<!-- #include file = "db.asp" -->
<%


'File Name: editstudent.asp
'Purpose:  To edit student record found in findstudent.asp

'declare variables
dim strcriteria
dim rsedit
set rsedit = server.createobject ("ADODB.recordset")


strssn = request.form("SSN")
If request.querystring("end") = 1 then
      session.Abandon
end if

strssn = session("SSN")

'select statement to find data in database
strsql = "select ssn, firstname, lastname,  NickName, emailadd, phone, picturefile  from student where ssn =  '" &  strssn & "'"


'Set the cursor type
rsedit.cursortype = 2

'open table
rsedit.open strsql, objconn

'Populate Recordset with Data
      set rsedit = objconn.execute (strsql)

%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Edit Student</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>

<%
'assign values to session variables

      fname = session("firstName")
      lname = session("lastName")
      nname = session("NickName")
      email = session("eMailAdd")
      phonenum = session("Phone")
      picture = session("picturefile")

%>
<%
'edit form with values from findstudent.asp
%>
<h1><p align="center"><span class="style3"><FONT COLOR="#8fbc8f">Edit Student Record For<br>
<%response.write strssn%></FONT> </span><BR></h1>

      <b> <font face="Arial, Helvetica, sans-serif">First Name:</font> </b>
      <input type = text name = "firstname" size = "26" value = "<%= session("firstname") %> "><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <b> <font face="Arial, Helvetica, sans-serif">Last Name:</font> </b>
    <input type = text  name = "lastname" size = "26" value = "<%= session("lastname") %>"><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face="Arial, Helvetica, sans-serif">
    <b>Nick Name:</b>
</font>
    <input type = text name = "NickName" size = "26" value = "<%= session("NickName") %>"><br>
    <b><font face="Arial, Helvetica, sans-serif">E-Mail Address:</font></b>
    <input type = text name = "emailadd" size = "26" value = "<%= session("EMailAdd") %>"><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<font face="Arial, Helvetica, sans-serif">
      <b>Phone:</b>
</font>
    <input type = text name = "Phone" size = "26" value = "<%= session("Phone") %>"><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<font face="Arial, Helvetica, sans-serif">
      <b>Picture:</b>
</font>
    <input type = text name = "Picture" size = "26" value = "<%= session("PictureFile") %>"><br>
<br>
<br>
      <form action = "editstudent.asp" method = post>
      <input type = "submit" name = "edit" value = "Submit Changes">
<br>
<br>
<br>
<a href="http://baeacd.uncg.edu/dcphilli/lab5/default.asp" title="Return" target="_parent">Return to Search Page</a>
</form>

<%'update the record in the recordset

     dim objcmd

     If Request.Form("editstudent.asp") <> "" Then
          set objcmd = server.createobject("ADODB.command")
          objcmd.activeconnection = objconn
          objcmd.commandtype = adcmdtext

          fname = Request.Form("firstName")
          lname = Request.Form("lastName")
          nname = Request.Form("NickName")
          email = Request.Form("eMailAdd")
          phonenum = Request.Form("Phone")
              picture = request.form("picturefile")

          editsql = "UPDATE student SET firstname = '" & fname & "', lastname = '" & lname & "', nickname = '" & nname & "', emailadd = '" & email & "', phone = '" & phonenum & "' where ssn = '" &  strssn & "'"
          objcmd.commandtext = editsql
          objcmd.execute
%>
            <h1><p align="center"><span class="style3"><FONT COLOR="#8fbc8f">Record has been updated For<br>
<%
End If
%>
<%
'close recordset and connection
rsedit.close
set rsedit = nothing
set objconn = nothing
%>

    </body>
</html>



0
 

Author Comment

by:dcphilli
ID: 9780963
Someone please help me with this updating existing record in database problem!
0
 
LVL 19

Expert Comment

by:Dexstar
ID: 9781254
Try this...

Basically, here is what I did.

I moved the "update" code to the TOP.  You should first check to see if the user is submitting new values.  If they are, then you should update the DB FIRST, and then read the DB to get the latest values.  And then display those in the form.

If the form is not being submitted, then you should just read the values from the DB.

Also, you had some things with session variables that didn't look necessary, so I took them out.

I didn't see where objconn is being created.  But I didn't see it in the one that you posted either, so I'm not sure what's up with that.  Maybe it's in db.asp!  That's probably it.

Try this file:
---
<!-- #include file = "db.asp" -->
<%
'File Name: editstudent.asp
'Purpose:  To edit student record found in findstudent.asp

'declare variables
dim strcriteria
dim rsedit
dim strSSN
dim objcmd

set rsedit = server.createobject ("ADODB.recordset")
strSSN = Request.form("SSN")

If request.querystring("end") = 1 then
     session.Abandon
end if

' Check to see if the form has been submitted.
' If it is, then perform the update
If Request.Form("Edit") <> "" Then
      set objcmd = server.createobject("ADODB.command")
      objcmd.activeconnection = objconn
      objcmd.commandtype = adcmdtext

      fname = Request.Form("firstName")
      lname = Request.Form("lastName")
      nname = Request.Form("NickName")
      email = Request.Form("eMailAdd")
      phonenum = Request.Form("Phone")
      picture = request.form("picturefile")

    editsql = "UPDATE student SET firstname = '" & fname & "', lastname = '" & lname & "', nickname = '" & nname & "', emailadd = '" & email & "', phone = '" & phonenum & "' where ssn = '" &  strssn & "'"
    objcmd.commandtext = editsql
    objcmd.execute
   
    ' Remember that we updated to display message later
    bUpdated = True
End If

' Now, whether or not there has been an update, get the latest values
strsql = "select ssn, firstname, lastname,  NickName, emailadd, phone, picturefile from student where ssn = '" &  strssn & "'"

'Set the cursor type
rsedit.cursortype = 2

'open table
rsedit.open strsql, objconn

'Populate Recordset with Data
set rsedit = objconn.execute (strsql)

%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Edit Student</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>

<h1><p align="center"><span class="style3"><FONT COLOR="#8fbc8f">Edit Student Record For<br>
<%=strssn%></FONT> </span><BR></h1>

     <form action = "editstudent.asp" method = post>
     <b> <font face="Arial, Helvetica, sans-serif">First Name:</font> </b>
     <input type = text name = "firstname" size = "26" value = "<%= rsedit("firstname") %> "><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <b> <font face="Arial, Helvetica, sans-serif">Last Name:</font> </b>
    <input type = text  name = "lastname" size = "26" value = "<%= rsedit("lastname") %>"><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face="Arial, Helvetica, sans-serif">
    <b>Nick Name:</b>
</font>
    <input type = text name = "NickName" size = "26" value = "<%= rsedit("NickName") %>"><br>
    <b><font face="Arial, Helvetica, sans-serif">E-Mail Address:</font></b>
    <input type = text name = "emailadd" size = "26" value = "<%= rsedit("EMailAdd") %>"><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<font face="Arial, Helvetica, sans-serif">
     <b>Phone:</b>
</font>
    <input type = text name = "Phone" size = "26" value = "<%= rsedit("Phone") %>"><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<font face="Arial, Helvetica, sans-serif">
     <b>Picture:</b>
</font>
    <input type = text name = "Picture" size = "26" value = "<%= rsedit("PictureFile") %>"><br>
<br>
<br>
     <input type = "submit" name = "edit" value = "Submit Changes">
</form>
<br>
<br>
<br>
<a href="http://baeacd.uncg.edu/dcphilli/lab5/default.asp" title="Return" target="_parent">Return to Search Page</a>
<%
      If bUpdated = True Then
%>
            <h1><p align="center"><span class="style3"><FONT COLOR="#8fbc8f">Record has been updated For<br><%=strssn%></font></span</h1>
<%
      End If
%>

<%
'close recordset and connection
rsedit.close
set rsedit = nothing
set objconn = nothing
%>

    </body>
</html>

0
 

Author Comment

by:dcphilli
ID: 9781375
Dexstar,

Thank you for the help, but unfortunately, they are working on our network, and I've lost my server connection and can't try anything right now.  

I hope that you'll still be checking when I get back to it later today.

0
 
LVL 19

Expert Comment

by:Dexstar
ID: 9781440
Yeah, I'll check back... :)

In the mean time, look at my file and compare it to yours, and see if you understand what I did.  Any thing that isn't clear, you should ask about.

Dex*
0
 

Author Comment

by:dcphilli
ID: 9783271
I rearranged everything, putting the edit statement on top and added the update if to print the confirmation message, but still no update, no confirmation message either, so it's not even getting that far evidently.
0
 
LVL 19

Expert Comment

by:Dexstar
ID: 9783291
Okay, try this...

1) Make a copy of your "editstudent.asp" file.
2) Replace your file with the EXACT file that I posted before.

Do that, and then tell me what errors / incorrect behavior you experience.  Include line number, if possible.

Dex*
0
 

Author Comment

by:dcphilli
ID: 9783386
Error Type:
Microsoft VBScript compilation (0x800A0411)
Name redefined
/dcphilli/Lab5/editstudent.asp, line 9, column 4

it was the dim ssn line - I commented that out and now I have

Error Type:
ADODB.Field (0x80020009)
Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.
/dcphilli/Lab5/editstudent.asp


by the way, the add page doesn't work either - keeps say primary key cannot be a null value.  If that gives any clues of something I could have done somewhere else that is effecting both pages.

thanks
0
 
LVL 19

Expert Comment

by:Dexstar
ID: 9783502
Let's do one thing at a time.  Maybe what you can learn from fixing this one will help you to fix the other one by yourself... :)

Try this file:

<!-- #include file = "db.asp" -->
<%
'File Name: editstudent.asp
'Purpose:  To edit student record found in findstudent.asp

'declare variables
dim strcriteria
dim rsedit
'dim strSSN
dim objcmd

set rsedit = server.createobject ("ADODB.recordset")
strSSN = Request.form("SSN")

If request.querystring("end") = 1 then
     session.Abandon
end if

' Check to see if the form has been submitted.
' If it is, then perform the update
If Request.Form("Edit") <> "" Then
     set objcmd = server.createobject("ADODB.command")
     objcmd.activeconnection = objconn
     objcmd.commandtype = adcmdtext

     fname = Request.Form("firstName")
     lname = Request.Form("lastName")
     nname = Request.Form("NickName")
     email = Request.Form("eMailAdd")
     phonenum = Request.Form("Phone")
     picture = request.form("picturefile")

    editsql = "UPDATE student SET firstname = '" & fname & "', lastname = '" & lname & "', nickname = '" & nname & "', emailadd = '" & email & "', phone = '" & phonenum & "' where ssn = '" &  strssn & "'"
    objcmd.commandtext = editsql
    objcmd.execute
   
    ' Remember that we updated to display message later
    bUpdated = True
End If

' Now, whether or not there has been an update, get the latest values
strsql = "select ssn, firstname, lastname,  NickName, emailadd, phone, picturefile from student where ssn = '" &  strssn & "'"

'Set the cursor type
rsedit.cursortype = 2

'open table
rsedit.open strsql, objconn

'Populate Recordset with Data
set rsedit = objconn.execute (strsql)

%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Edit Student</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>

<% If Not rsedit.EOF Then %>
<h1><p align="center"><span class="style3"><FONT COLOR="#8fbc8f">Edit Student Record For<br>
<%=strssn%></FONT> </span><BR></h1>

     <form action = "editstudent.asp" method = post>
     <b> <font face="Arial, Helvetica, sans-serif">First Name:</font> </b>
     <input type = text name = "firstname" size = "26" value = "<%= rsedit("firstname") %> "><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <b> <font face="Arial, Helvetica, sans-serif">Last Name:</font> </b>
    <input type = text  name = "lastname" size = "26" value = "<%= rsedit("lastname") %>"><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face="Arial, Helvetica, sans-serif">
    <b>Nick Name:</b>
</font>
    <input type = text name = "NickName" size = "26" value = "<%= rsedit("NickName") %>"><br>
    <b><font face="Arial, Helvetica, sans-serif">E-Mail Address:</font></b>
    <input type = text name = "emailadd" size = "26" value = "<%= rsedit("EMailAdd") %>"><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<font face="Arial, Helvetica, sans-serif">
     <b>Phone:</b>
</font>
    <input type = text name = "Phone" size = "26" value = "<%= rsedit("Phone") %>"><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<font face="Arial, Helvetica, sans-serif">
     <b>Picture:</b>
</font>
    <input type = text name = "Picture" size = "26" value = "<%= rsedit("PictureFile") %>"><br>
<br>
<br>
     <input type = "submit" name = "edit" value = "Submit Changes">
</form>
<%
Else
      If ( Len(strSSN) > 0 ) Then
%>
      Invalid SSN!
<%
      Else
%>
      SSN Not Found: <=%strSSN%>
<%
      End If
End If
%>
<br>
<br>
<br>
<a href="http://baeacd.uncg.edu/dcphilli/lab5/default.asp" title="Return" target="_parent">Return to Search Page</a>
<%
     If bUpdated = True Then
%>
          <h1><p align="center"><span class="style3"><FONT COLOR="#8fbc8f">Record has been updated For<br><%=strssn%></font></span</h1>
<%
     End If
%>

<%
'close recordset and connection
rsedit.close
set rsedit = nothing
set objconn = nothing
%>

    </body>
</html>
0
 

Author Comment

by:dcphilli
ID: 9783523
now getting the "record has been updated for" message without any form to change any fields, and the strssn is not feeding to finish the message.
0
 
LVL 19

Expert Comment

by:Dexstar
ID: 9783570
@dcphilli:

There are still a few things wrong.  I looked at your "findstudent.asp" page.
In the form that looks like this:
      <form action = "editstudent.asp" method = post>
      <input type = "submit" name="Edit" value="Edit Student">
      </form>

You need to add an input to pass in the SSN, like this:
      <form action = "editstudent.asp" method = post>
      <input type = "submit" name="Edit" value="Edit Student">
      <input type = "hidden" name="SSN" value="<%=strssn%>">
      </form>

Do that, and then use this for your editstudent.asp file:
<!-- #include file = "db.asp" -->
<%
'File Name: editstudent.asp
'Purpose:  To edit student record found in findstudent.asp

'declare variables
dim strcriteria
dim rsedit
'dim strSSN
dim objcmd

set rsedit = server.createobject ("ADODB.recordset")
strSSN = Request.form("SSN")

If request.querystring("end") = 1 then
     session.Abandon
end if

' Check to see if the form has been submitted.
' If it is, then perform the update
If Request.Form("SaveChanges") = 1 Then
     set objcmd = server.createobject("ADODB.command")
     objcmd.activeconnection = objconn
     objcmd.commandtype = adcmdtext

     fname = Request.Form("firstName")
     lname = Request.Form("lastName")
     nname = Request.Form("NickName")
     email = Request.Form("eMailAdd")
     phonenum = Request.Form("Phone")
     picture = request.form("picturefile")

    editsql = "UPDATE student SET firstname = '" & fname & "', lastname = '" & lname & "', nickname = '" & nname & "', emailadd = '" & email & "', phone = '" & phonenum & "' where ssn = '" &  strssn & "'"
    objcmd.commandtext = editsql
    objcmd.execute
   
    ' Remember that we updated to display message later
    bUpdated = True
End If

' Now, whether or not there has been an update, get the latest values
strsql = "select ssn, firstname, lastname,  NickName, emailadd, phone, picturefile from student where ssn = '" &  strssn & "'"

'Set the cursor type
rsedit.cursortype = 2

'open table
rsedit.open strsql, objconn

'Populate Recordset with Data
set rsedit = objconn.execute (strsql)

%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Edit Student</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>

<% If Not rsedit.EOF Then %>
<h1><p align="center"><span class="style3"><FONT COLOR="#8fbc8f">Edit Student Record For<br>
<%=strssn%></FONT> </span><BR></h1>

     <form action = "editstudent.asp" method = post>
     <b> <font face="Arial, Helvetica, sans-serif">First Name:</font> </b>
     <input type = text name = "firstname" size = "26" value = "<%= rsedit("firstname") %> "><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <b> <font face="Arial, Helvetica, sans-serif">Last Name:</font> </b>
    <input type = text  name = "lastname" size = "26" value = "<%= rsedit("lastname") %>"><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face="Arial, Helvetica, sans-serif">
    <b>Nick Name:</b>
</font>
    <input type = text name = "NickName" size = "26" value = "<%= rsedit("NickName") %>"><br>
    <b><font face="Arial, Helvetica, sans-serif">E-Mail Address:</font></b>
    <input type = text name = "emailadd" size = "26" value = "<%= rsedit("EMailAdd") %>"><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<font face="Arial, Helvetica, sans-serif">
     <b>Phone:</b>
</font>
    <input type = text name = "Phone" size = "26" value = "<%= rsedit("Phone") %>"><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<font face="Arial, Helvetica, sans-serif">
     <b>Picture:</b>
</font>
    <input type = text name = "Picture" size = "26" value = "<%= rsedit("PictureFile") %>"><br>
<br>
<br>
     <input type = "submit" name = "edit" value = "Submit Changes">
     <input type = "hidden" name = "SaveChanges" value="1">
</form>
<%
Else
      If ( Len(strSSN) > 0 ) Then
%>
      Invalid SSN!
<%
      Else
%>
      SSN Not Found: <=%strSSN%>
<%
      End If
End If
%>
<br>
<br>
<br>
<a href="http://baeacd.uncg.edu/dcphilli/lab5/default.asp" title="Return" target="_parent">Return to Search Page</a>
<%
     If bUpdated = True Then
%>
          <h1><p align="center"><span class="style3"><FONT COLOR="#8fbc8f">Record has been updated For<br><%=strssn%></font></span</h1>
<%
     End If
%>

<%
'close recordset and connection
rsedit.close
set rsedit = nothing
set objconn = nothing
%>

    </body>
</html>

0
 

Author Comment

by:dcphilli
ID: 9783582
I saw where you put in an error checking of

if len(strssn) < 0 then
invalid ssn

I'm getting that msg in the top left corner

0
 
LVL 19

Expert Comment

by:Dexstar
ID: 9783593
That's just a safety check to see if the SSN is correct or not.  If you see that message, then the SSN wasn't passed from findstudent.asp to editstudent.asp.

You should edit "findstudent.asp" like I suggested.  Here is the change you need to make:

In the form that looks like this:
     <form action = "editstudent.asp" method = post>
     <input type = "submit" name="Edit" value="Edit Student">
     </form>

You need to add an input to pass in the SSN, like this:
     <form action = "editstudent.asp" method = post>
     <input type = "submit" name="Edit" value="Edit Student">
     <input type = "hidden" name="SSN" value="<%=strssn%>">
     </form>
0
 

Author Comment

by:dcphilli
ID: 9783622
Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80004005)
[Microsoft][ODBC Microsoft Access Driver] Field 'student.FirstName' cannot be a zero-length string.
/dcphilli/Lab5/editstudent.asp, line 35


this is line 35
      set rsfind = objconn.execute (strsql)
0
 
LVL 19

Expert Comment

by:Dexstar
ID: 9783733
It shouldn't be trying to submit the changes, because there haven't been any yet... :)  Try this:

<!-- #include file = "db.asp" -->
<%
'File Name: editstudent.asp
'Purpose:  To edit student record found in findstudent.asp

'declare variables
dim strcriteria
dim rsedit
'dim strSSN
dim objcmd

set rsedit = server.createobject ("ADODB.recordset")
strSSN = Request.form("SSN")

If request.querystring("end") = 1 then
     session.Abandon
end if

' Check to see if the form has been submitted.
' If it is, then perform the update
If Request.Form("SaveChanges") = "True" Then
     set objcmd = server.createobject("ADODB.command")
     objcmd.activeconnection = objconn
     objcmd.commandtype = adcmdtext

     fname = Request.Form("firstName")
     lname = Request.Form("lastName")
     nname = Request.Form("NickName")
     email = Request.Form("eMailAdd")
     phonenum = Request.Form("Phone")
     picture = request.form("picturefile")

    editsql = "UPDATE student SET firstname = '" & fname & "', lastname = '" & lname & "', nickname = '" & nname & "', emailadd = '" & email & "', phone = '" & phonenum & "' where ssn = '" &  strssn & "'"
    objcmd.commandtext = editsql
    objcmd.execute
   
    ' Remember that we updated to display message later
    bUpdated = True
End If

' Now, whether or not there has been an update, get the latest values
strsql = "select ssn, firstname, lastname,  NickName, emailadd, phone, picturefile from student where ssn = '" &  strssn & "'"

'Set the cursor type
rsedit.cursortype = 2

'open table
rsedit.open strsql, objconn

'Populate Recordset with Data
set rsedit = objconn.execute (strsql)

%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Edit Student</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>

<% If Not rsedit.EOF Then %>
<h1><p align="center"><span class="style3"><FONT COLOR="#8fbc8f">Edit Student Record For<br>
<%=strssn%></FONT> </span><BR></h1>

     <form action = "editstudent.asp" method = post>
     <b> <font face="Arial, Helvetica, sans-serif">First Name:</font> </b>
     <input type = text name = "firstname" size = "26" value = "<%= rsedit("firstname") %> "><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <b> <font face="Arial, Helvetica, sans-serif">Last Name:</font> </b>
    <input type = text  name = "lastname" size = "26" value = "<%= rsedit("lastname") %>"><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face="Arial, Helvetica, sans-serif">
    <b>Nick Name:</b>
</font>
    <input type = text name = "NickName" size = "26" value = "<%= rsedit("NickName") %>"><br>
    <b><font face="Arial, Helvetica, sans-serif">E-Mail Address:</font></b>
    <input type = text name = "emailadd" size = "26" value = "<%= rsedit("EMailAdd") %>"><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<font face="Arial, Helvetica, sans-serif">
     <b>Phone:</b>
</font>
    <input type = text name = "Phone" size = "26" value = "<%= rsedit("Phone") %>"><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<font face="Arial, Helvetica, sans-serif">
     <b>Picture:</b>
</font>
    <input type = text name = "Picture" size = "26" value = "<%= rsedit("PictureFile") %>"><br>
<br>
<br>
     <input type = "submit" name = "edit" value = "Submit Changes">
     <input type = "hidden" name = "SaveChanges" value="True">
</form>
<%
Else
      If ( Len(strSSN) > 0 ) Then
%>
      Invalid SSN!
<%
      Else
%>
      SSN Not Found: <=%strSSN%>
<%
      End If
End If
%>
<br>
<br>
<br>
<a href="http://baeacd.uncg.edu/dcphilli/lab5/default.asp" title="Return" target="_parent">Return to Search Page</a>
<%
     If bUpdated = True Then
%>
          <h1><p align="center"><span class="style3"><FONT COLOR="#8fbc8f">Record has been updated For<br><%=strssn%></font></span</h1>
<%
     End If
%>

<%
'close recordset and connection
rsedit.close
set rsedit = nothing
set objconn = nothing
%>

    </body>
</html>
0
 

Author Comment

by:dcphilli
ID: 9783757
same thing

SSN Not Found: <=%strSSN%>


Return to Search Page
Record has been updated For

0
 
LVL 19

Accepted Solution

by:
Dexstar earned 300 total points
ID: 9783819
Okay, well, at least we're a little closer.  I forgot to include the SSN as a hidden member in the form on editstudent.asp.  This should fix that:

<!-- #include file = "db.asp" -->
<%
'File Name: editstudent.asp
'Purpose:  To edit student record found in findstudent.asp

'declare variables
dim strcriteria
dim rsedit
'dim strSSN
dim objcmd

set rsedit = server.createobject ("ADODB.recordset")
strSSN = Request.form("SSN")

If request.querystring("end") = 1 then
     session.Abandon
end if

' Check to see if the form has been submitted.
' If it is, then perform the update
If ( (Request.Form("SaveChanges") = "True") And (Len(strSSN) > 0) ) Then
     set objcmd = server.createobject("ADODB.command")
     objcmd.activeconnection = objconn
     objcmd.commandtype = adcmdtext

     fname = Request.Form("firstName")
     lname = Request.Form("lastName")
     nname = Request.Form("NickName")
     email = Request.Form("eMailAdd")
     phonenum = Request.Form("Phone")
     picture = request.form("picturefile")

    editsql = "UPDATE student SET firstname = '" & fname & "', lastname = '" & lname & "', nickname = '" & nname & "', emailadd = '" & email & "', phone = '" & phonenum & "' where ssn = '" &  strssn & "'"
    objcmd.commandtext = editsql
    objcmd.execute
   
    ' Remember that we updated to display message later
    bUpdated = True
End If

' Now, whether or not there has been an update, get the latest values
strsql = "select ssn, firstname, lastname,  NickName, emailadd, phone, picturefile from student where ssn = '" &  strssn & "'"

'Set the cursor type
rsedit.cursortype = 2

'open table
rsedit.open strsql, objconn

'Populate Recordset with Data
set rsedit = objconn.execute (strsql)

%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Edit Student</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>

<% If Not rsedit.EOF Then %>
<h1><p align="center"><span class="style3"><FONT COLOR="#8fbc8f">Edit Student Record For<br>
<%=strssn%></FONT> </span><BR></h1>

     <form action = "editstudent.asp" method = post>
     <b> <font face="Arial, Helvetica, sans-serif">First Name:</font> </b>
     <input type = text name = "firstname" size = "26" value = "<%= rsedit("firstname") %> "><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <b> <font face="Arial, Helvetica, sans-serif">Last Name:</font> </b>
    <input type = text  name = "lastname" size = "26" value = "<%= rsedit("lastname") %>"><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face="Arial, Helvetica, sans-serif">
    <b>Nick Name:</b>
</font>
    <input type = text name = "NickName" size = "26" value = "<%= rsedit("NickName") %>"><br>
    <b><font face="Arial, Helvetica, sans-serif">E-Mail Address:</font></b>
    <input type = text name = "emailadd" size = "26" value = "<%= rsedit("EMailAdd") %>"><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<font face="Arial, Helvetica, sans-serif">
     <b>Phone:</b>
</font>
    <input type = text name = "Phone" size = "26" value = "<%= rsedit("Phone") %>"><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<font face="Arial, Helvetica, sans-serif">
     <b>Picture:</b>
</font>
    <input type = text name = "Picture" size = "26" value = "<%= rsedit("PictureFile") %>"><br>
<br>
<br>
     <input type = "submit" name = "edit" value = "Submit Changes">
     <input type = "hidden" name = "SSN" value="<%=strSSN%>">
     <input type = "hidden" name = "SaveChanges" value="True">
</form>
<%
Else
      If ( Len(strSSN) > 0 ) Then
%>
      Invalid SSN!
<%
      Else
%>
      SSN Not Found: <%=strSSN%>
<%
      End If
End If
%>
<br>
<br>
<br>
<a href="http://baeacd.uncg.edu/dcphilli/lab5/default.asp" title="Return" target="_parent">Return to Search Page</a>
<%
     If bUpdated = True Then
%>
          <h1><p align="center"><span class="style3"><FONT COLOR="#8fbc8f">Record has been updated For<br><%=strssn%></font></span</h1>
<%
     End If
%>

<%
'close recordset and connection
rsedit.close
set rsedit = nothing
set objconn = nothing
%>

    </body>
</html>
0
 

Author Comment

by:dcphilli
ID: 9783831
It works, it works, it works,


Okay.  Do you have time to help me tackle the add pages?

I think I know what is not happening, but I can't see why.

0
 
LVL 19

Expert Comment

by:Dexstar
ID: 9783842
Hurray!  I'm glad you got it working!

Sure, I can help you with the add pages, but you should open a new question so everyone else can have a chance too.

Dex*
0
 

Author Comment

by:dcphilli
ID: 9783863
I was planning too.

Watch for it
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

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…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

717 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