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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Edit record from web page?

Status
Not open for further replies.

DrDan2

Technical User
Nov 22, 2002
24
GB
I'm new to Coldfusion but I'm learning fast. Hoever I'm kinda stumped at how I can get a user to edit their details. I have a page where they can send their details to be inputed into the Access 2000 database and a page that can view those details. But if the somone changes address or something, I'd like them to be able to change those details. Any suggestions? Please.

Thanks a bunch.
 

Sounds like a loaded question, actually.

You can pull up the existing values for their data like:

Code:
<CFQUERY name=&quot;userData&quot; ...>
  SELECT *
    FROM usertable 
   WHERE userid = #myUserid#
</CFQUERY>

         :

<CFIF userdata.RecordCount GT 0>
  <CFOUTPUT>
  <FORM name=&quot;editData&quot; ...>
     User Name <input type=&quot;text&quot; name=&quot;username&quot; value=&quot;#userdata.username#&quot;><br />

     Address <input type=&quot;text&quot; name=&quot;useraddress&quot; value=&quot;#userdata.useraddress#&quot;><br />
         :
     <input type=&quot;hidden&quot; name=&quot;userid&quot; value=&quot;#myUserid#&quot;>
  </FORM> 
  </CFOUTPUT>
</CFIF>

then your action page would simply do an UPDATE, rather than an INSERT

Code:
<CFQUERY name=&quot;updateUser&quot; ...>
  UPDATE usertable 
     SET username = '#FORM.username#',
         useraddress = '#FORM.useraddress#',
             :
   WHERE userid = #FORM.myUserid#
   LIMIT 1
</CFQUERY>

or, if you prefer,

Code:
<cfupdate tableName=&quot;usertable&quot; formFields=&quot;userid,username,useraddress&quot; dataSource=... >


With a little clever coding, a well-placed CFIF block, and another hidden field in the form to designate &quot;insert&quot; or &quot;update&quot; mode, you can usually combine both the &quot;create a new user&quot; and &quot;update a user&quot; forms into the same page (same with the action page)... possibly making it a little easier to maintain (how often have I added a form field to the create form, but forgotten to add it to the update form so the user could edit it).







Hope it helps,
-Carl
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top