Solved

editing database records

Posted on 2003-11-18
28
429 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
  • 15
  • 13
28 Comments
 
LVL 19

Expert Comment

by:Dexstar
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:dcphilli
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Someone please help me with this updating existing record in database problem!
0
 
LVL 19

Expert Comment

by:Dexstar
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 19

Expert Comment

by:Dexstar
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
@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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I was planning too.

Watch for it
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now