Tutorial | 10 Days of learning
Previous section: Deleting Records
Learning Purpose: Learn the basic operation of the database--Modify the record
First look at the code: (Save as exam8.asp can be)
<%
Set Conn=server.createobject ("Adodb.connection")
Conn.Open "Driver={microsoft Access Driver (*.mdb)};d bq=" &server.mappath ("Data/guestbook.mdb")
Exec= "SELECT * from guest where id=" &request.form ("id")
Set Rs=server.createobject ("Adodb.recordset")
Rs.Open Exec,conn
%>
<form name= "Form1" method= "Post" action= "modifysave.asp" >
<table width= "748" border= "0" cellspacing= "0" cellpadding= "0" >
<tr>
<td>name</td>
<td>tel</td>
<td>message</td>
</tr>
<tr>
<td>
<input type= "text" name= "name" value= "<%=rs (" name ")%>" >
</td>
<td>
<input type= "Text" name= "tel" value= "<%=rs (" tel ")%>" >
</td>
<td>
<input type= "text" name= "message" value= "<%=rs (" message ")%>" >
<input type= "Submit" name= "Submission" value= "submitted" >
<input type= "hidden" name= id "value=" <%=request.form ("id")%> ">
</td>
</tr>
</table>
</form>
<%
Rs.close
Set rs=nothing
Conn.close
Set conn=nothing
%>
There's nothing wrong with analyzing this code. The function of this code is to accept the ID of the previous page and then display this record, the text box is the place where the input is also displayed, if you need to modify the following changes to submit, if you do not need to modify the Submit button can be directly.
Here because this tutorial is suitable for beginners, so also give the form content presented, save the following code as a 8.htm file
<form name= "Form1" method= "Post" action= "exam8.asp" >
Please enter the ID of the record you want to modify:
<input type= "text" name= "id" >
<br>
<input type= "Submit" name= "Submission" value= "submitted" >
</form>
Here's another thing that hasn't been said before, that's the hidden form element: The hidden element, where the value is not entered by the user, and is submitted as a single table for passing variables.
Here is the code for modifysave.asp :
<%
Set Conn=server.createobject ("Adodb.connection")
Conn.Open "Driver={microsoft Access Driver (*.mdb)};d bq=" &server.mappath ("Data/guestbook.mdb")
Exec= "SELECT * from guest where id=" &request.form ("id")
Set Rs=server.createobject ("Adodb.recordset")
Rs.Open exec,conn,1,3
RS ("name") =request.form ("name")
RS ("tel") =request.form ("tel")
RS (' message ') =request.form ("message")
Rs.update
Rs.close
Set rs=nothing
Conn.close
Set conn=nothing
%>
Here, the Rs.Open exec,conn,1,3 after the argument is 1, 3, which I have mentioned before, modify the record will use 1, 3. In fact, modify the record is easy to understand, the Recordset is Rs,rs ("AA") is the current record AA field of things, let it equal to the new data Request.Form ("AA") of course modified, but finally don't forget to save, that is rs.update!
Here, the records of the search, read, modify, insert all said, through the most basic things can make complex things, the outside of the large database: News system, the guest book is a little more than the field. Today's example of the code is combined with the previous database, later go back to debugging analysis.
Everyone testing the process: First run 8.htm files
After you click Submit, modify the record in the following figure
After the modification, click Submit, as shown in the following figure, indicating that the modification was successful
You can use the previous duqu.asp to show whether you have successfully modified
Next section: Introduction to Components