Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating a record in ASP

Status
Not open for further replies.

Garabaldi

Technical User
Jan 16, 2002
61
CA
Hi folks,

I need some help in setting up a form in ASP so that people can go in and update a record in the database.

Right now my form is working properly. It is taking all the fields and dumping them into an SQL table. However I need to fix it so that they can enter a record number and have that form autopopulate and if they make any changes on that form the changes will overwrite what is currently in that record.

Thanks,
 
[tt]Here's one way to do this:

1. Create a second page with a form and a dropdownbox containing the field of your choice from the sql table.

2. Have that page submit to something like this:
[/tt]
<%
reqid = request(&quot;customersdropdown&quot;)
session(&quot;id&quot;) = reqid
sql = &quot;Select * from Customers where id = &quot; & reqid '&quot;>&quot;
Dim myRSc
set myRSc=server.createobject(&quot;adodb.recordset&quot;)
myRSc.open sql, &quot;dsn=mysqldatabase&quot;
%>
<html>
<head>
<title>Your Title</title>
</head>
<body bgcolor=&quot;#006699&quot; link=&quot;#FFFFFF&quot; vlink=&quot;#00FFFF&quot;>


<h1 align=&quot;center&quot;><font color=&quot;#FFFFFF&quot;><!--webbot bot=&quot;Navigation&quot; S-Type=&quot;banner&quot; S-Rendering=&quot;graphics&quot;
S-Orientation B-Include-Home B-Include-Up U-Page S-Target startspan -->You are about to edit CUSTOMER<!--webbot bot=&quot;Navigation&quot; endspan i-checksum=&quot;1877&quot; --></font>
</h1>


<h1 align=&quot;center&quot;><font color=&quot;#FFFF00&quot;>  </font><font color=&quot;#FFFFFF&quot; size=&quot;7&quot;><%=myRSc(&quot;company&quot;)%></font>
</p>


</h1>


<p align=&quot;center&quot;><font color=&quot;#FFFFFF&quot; size=&quot;3&quot;>Make sure this is the job number
you intend to edit. If not, make the correct selection <a href=&quot;default.asp&quot;>here</a>.</font>
</p>
<form method=&quot;POST&quot; action=&quot;updatepage.asp&quot;>
<table border=&quot;0&quot; width=&quot;1069&quot; height=&quot;553&quot;>
<tr>
<td width=&quot;108&quot; align=&quot;right&quot; height=&quot;19&quot;><font color=&quot;#FFFFFF&quot;><b>Acct. Number:</b></font></td>
<td width=&quot;344&quot; height=&quot;19&quot;>
<p align=&quot;left&quot;><font color=&quot;#FFFFFF&quot;><b><input type=&quot;text&quot; name=&quot;accnumber&quot; size=&quot;10&quot; value=&quot;<%=myRSc(&quot;accnumber&quot;)%>&quot;></b></font></p>
</td>
<td width=&quot;146&quot; height=&quot;19&quot;></td>
<td width=&quot;153&quot; height=&quot;19&quot;></td>
<td width=&quot;264&quot; height=&quot;19&quot;></td>
<td width=&quot;3&quot; height=&quot;19&quot;></td>
</tr>
<tr>
<td width=&quot;108&quot; align=&quot;right&quot; height=&quot;25&quot;><font color=&quot;#FFFFFF&quot;><b>Company:</b></font></td>
<td width=&quot;344&quot; height=&quot;25&quot;>
<p align=&quot;left&quot;><font color=&quot;#FFFFFF&quot;><b><input type=&quot;text&quot; name=&quot;company&quot; size=&quot;40&quot; value=&quot;<%=myRSc(&quot;company&quot;)%>&quot;></b></font></p>
</td>
<td width=&quot;146&quot; height=&quot;25&quot;></td>
<td width=&quot;153&quot; height=&quot;25&quot;></td>
<td width=&quot;264&quot; height=&quot;25&quot;></td>
<td width=&quot;3&quot; height=&quot;25&quot;></td>
</tr>
<tr>
<td width=&quot;108&quot; align=&quot;right&quot; height=&quot;25&quot;><font color=&quot;#FFFFFF&quot;><b>Address1:</b></font></td>
<td width=&quot;496&quot; colspan=&quot;2&quot; height=&quot;25&quot;><font color=&quot;#FFFFFF&quot;><b><input type=&quot;text&quot; name=&quot;address1&quot; size=&quot;40&quot; value=&quot;<%=myRSc(&quot;address1&quot;)%>&quot;> </b></font></td>
<td width=&quot;153&quot; height=&quot;25&quot;></td>
<td width=&quot;264&quot; height=&quot;25&quot;></td>
<td width=&quot;3&quot; height=&quot;25&quot;></td>
</tr>
<tr>
<td width=&quot;108&quot; align=&quot;right&quot; height=&quot;25&quot;><font color=&quot;#FFFFFF&quot;><b>Address2:</b></font></td>
<td width=&quot;496&quot; colspan=&quot;2&quot; height=&quot;25&quot;><font color=&quot;#FFFFFF&quot;><b><input type=&quot;text&quot; name=&quot;address2&quot; size=&quot;40&quot; value=&quot;<%=myRSc(&quot;address2&quot;)%>&quot;></b></font></td>
<td width=&quot;153&quot; height=&quot;25&quot;></td>
<td width=&quot;264&quot; height=&quot;25&quot;></td>
<td width=&quot;3&quot; height=&quot;25&quot;></td>
</tr>
<tr>
<td width=&quot;108&quot; align=&quot;right&quot; height=&quot;25&quot;><font color=&quot;#FFFFFF&quot;><b>City:</b></font></td>
<td width=&quot;344&quot; height=&quot;25&quot;><font color=&quot;#FFFFFF&quot;><b><input type=&quot;text&quot; name=&quot;city&quot; size=&quot;25&quot; value=&quot;<%=myRSc(&quot;city&quot;)%>&quot;></b></font></td>
<td width=&quot;146&quot; align=&quot;right&quot; height=&quot;25&quot;><font color=&quot;#FFFFFF&quot;><b>State:</b></font></td>
<td width=&quot;153&quot; height=&quot;25&quot;>
<p align=&quot;left&quot;><font color=&quot;#FFFFFF&quot;><b><input type=&quot;text&quot; name=&quot;state&quot; size=&quot;5&quot; value=&quot;<%=myRSc(&quot;state&quot;)%>&quot;></b></font></p>
</td>
<td width=&quot;264&quot; align=&quot;right&quot; height=&quot;25&quot;><font color=&quot;#FFFFFF&quot;><b>Zip Code:</b></font><font color=&quot;#FFFFFF&quot;><b><input type=&quot;text&quot; name=&quot;zip&quot; size=&quot;15&quot; value=&quot;<%=myRSc(&quot;zip&quot;)%>&quot;></b></font></td>
<td width=&quot;3&quot; height=&quot;25&quot;></td>
</tr>
<tr>
<td width=&quot;108&quot; align=&quot;right&quot; height=&quot;25&quot;><font color=&quot;#FFFFFF&quot;><b>Country:</b></font></td>
<td width=&quot;344&quot; height=&quot;25&quot;><font color=&quot;#FFFFFF&quot;><b><input type=&quot;text&quot; name=&quot;country&quot; size=&quot;30&quot; value=&quot;<%=myRSc(&quot;country&quot;)%>&quot;></b></font></td>
<td width=&quot;146&quot; align=&quot;right&quot; height=&quot;25&quot;></td>
<td width=&quot;153&quot; height=&quot;25&quot;></td>
<td width=&quot;264&quot; align=&quot;right&quot; height=&quot;25&quot;></td>
<td width=&quot;3&quot; height=&quot;25&quot;></td>
</tr>
<tr>
<td width=&quot;108&quot; align=&quot;right&quot; height=&quot;25&quot;><font color=&quot;#FFFFFF&quot;><b>Phone:</b></font></td>
<td width=&quot;344&quot; height=&quot;25&quot;><font color=&quot;#FFFFFF&quot;><b><input type=&quot;text&quot; name=&quot;phone&quot; size=&quot;20&quot; value=&quot;<%=myRSc(&quot;phone&quot;)%>&quot;></b></font></td>
<td width=&quot;146&quot; align=&quot;right&quot; height=&quot;25&quot;><font color=&quot;#FFFFFF&quot;><b>Fax:</b></font></td>
<td width=&quot;153&quot; height=&quot;25&quot;>
<p align=&quot;left&quot;><font color=&quot;#FFFFFF&quot;><b><input type=&quot;text&quot; name=&quot;fax&quot; size=&quot;20&quot; value=&quot;<%=myRSc(&quot;fax&quot;)%>&quot;></b></font></p>
</td>
</table>
<p align=&quot;center&quot;> <input type=&quot;submit&quot; value=&quot;Submit&quot; name=&quot;B1&quot;>  
<input type=&quot;reset&quot; value=&quot;Reset&quot; name=&quot;B2&quot;></p>
</form>
<p> </p>
</body>
</html>
2a. [tt]This page will populate your table with everything you want to pull from the database and display it for updaing. Then this form is submitted to another page (3)[/tt]
**************************************
3. <%
sql = &quot;UPDATE Customers SET &quot;
sql = sql & &quot;accnumber = '&quot; & request.form(&quot;accnumber&quot;) & &quot;',&quot;
sql = sql & &quot;company = '&quot; & request.form(&quot;company&quot;) & &quot;',&quot;
sql = sql & &quot;address1 = '&quot; & request.form(&quot;address1&quot;) & &quot;',&quot;
sql = sql & &quot;address2 = '&quot; & request.form(&quot;address2&quot;) & &quot;',&quot;
sql = sql & &quot;city = '&quot; & request.form(&quot;city&quot;) & &quot;',&quot;
sql = sql & &quot;state = '&quot; & request.form(&quot;state&quot;) & &quot;',&quot;
sql = sql & &quot;zip = '&quot; & request.form(&quot;zip&quot;) & &quot;',&quot;
sql = sql & &quot;country = '&quot; & request.form(&quot;country&quot;) & &quot;',&quot;
sql = sql & &quot;phone = '&quot; & request.form(&quot;phone&quot;) & &quot;',&quot;

**************** This recordset allows me to ***********
******************* display my changes *****************
Dim RScfinal
set RScfinal=server.createobject(&quot;adodb.recordset&quot;)
RScfinal.open sql, &quot;dsn=QBooks&quot;
**************** This recordset allows me to ***********
******************* display my changes *****************


I hope it helps...

[tt]

&quot;The reward of one duty done is the power to fulfill another&quot;[/tt]
--------------------------------------------
[afro][love][medal][noevil][pc3]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top