4 Replies Latest reply: Sep 14, 2012 2:32 PM by Steve Skinner RSS

    Need to update a record on page load. How? (ASP/VBScript)

    Steve Skinner Community Member

      The standard Update Record behavior requires a form on the page, plus a recordset to identify the value to be updated. In my scenario, the value for the record to be updated is already in the URL as the ID. I just don't know how to write it myself and Dreamweaver won't do this.

       

      The page I want to do this on is a record detail page, so there is already a record ID already present in the querystring. The record is new until a user views it, and what I need is something that just writes a simple value to one field in the table for the record being viewed. This is it in a nutshell:

       

      Using the value from the ID in the URL querystring, update the "viewed" field in a specific table with the value of "y".

      This would be the first operation as the page loads and then the page would load and show the data that it already does.

       

      I'd be happy with raw code is someone is generous enough to provide that, or perhaps some instructional help on reverse engineering the standard update record code generated by Dreamweaver. Or, if you know of any extensions designed to do this - I'd be interested in that too!

       

      My app I'm working on is in ASP/vbscript.

       

      Subject line edited by moderator to indicate server model

        • 1. Re: Need to update a record on page load. How?
          Sudarshan Thiagarajan CommunityMVP

          Pretty simple.

           

          Create a form that is hidden with no submit button.

           

          Add this code to your page:

           

          onload="document.Formname.submit();"

          Change Formname to whatever name you've set for your form.

           

          Make the form submit action update the record of 'viewed' field to auto-increment.

           

          Trust this helps!

          • 2. Re: Need to update a record on page load. How?
            Steve Skinner Community Member

            Hi Sudarshan,

             

            I appreciate your reponse, but that doesn't solve my problem. The field I need to populate is not an auto-increment field. It's a specific value. I did try your method though but it did not work.

             

            When the detail page loads, a specific field in a table for the record ID being viewed needs to updated with a value, which is basically used to mark the record as being viewed by the user.

            • 3. Re: Need to update a record on page load. How? (ASP/VBScript)
              bregent CommunityMVP

              >Using the value from the ID in the URL querystring,

              >update the "viewed" field in a specific table with the value of "y".

               

              Be careful  - depending on what you are doing, it's usually not safe to to an update based on a querystring value - it's too easy for someone to mess with these. Sudarshan's solution for posting the form to DW server behavior is good, but I wouldn't even use a form for this. Tell us more about the nature of the data and we can provide a solution.

              • 4. Re: Need to update a record on page load. How? (ASP/VBScript)
                Steve Skinner Community Member

                Good point! I wasn't thinking about how that would make the app vulnerable to sql injection.

                 

                The function I want to perform is similar to how an email changes from unread to read when you view it. I simple want the records being viewed to take on the status of being read or "viewed". Perhaps I'm going about this in the wrong way, but I've been planning to use a database field as the indicator of whether a record has a viewed status or not. Null value is new, and a value of "y" (yes) meaning the value is viewed/read.

                 

                If you have a better recommendation, I'm all ears.