Results 1 to 4 of 4

Thread: [RESOLVED] Update result value?

  1. #1

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945

    Resolved [RESOLVED] Update result value?

    I have a bunch of data where I'm allowing people to mass-modify records.

    Example:
    Contract A - active
    Contract B - active
    Contract C - not active

    The 'active' field is a select box and they can change one or all of them all at once. So then I have a simple update statement:

    Code:
    UPDATE DTCONTRACT SET active = 1 - active WHERE CONTRACT_ID = 'x' AND active != $val
    $val = whatever they selected in the box.

    But my dilemma is this: I have to have an audit trail for what was changed. So how do I check if that specific record actually got updated? I currently have this (and I apologize that it's in PHP but that's what it's written in... but the idea is generally the same):

    Code:
    foreach($_POST as $key => $val)
        {
            // UPDATE active status of contract
            if(substr($key, 0, 7) == 'active_')
            {
                $query = "UPDATE DTCONTRACT SET active = 1 - active WHERE CONTRACT_ID = '" . substr($key,7) . "' AND active != $val";
                $result = $ehandle->update_query($query);
                if($result)
                    $tbox->log("Updated active status for contract: ".substr($key,7), substr($key,7));        
            }
        }
    But the result is always valid so it logs the change... so is there something I can check to see if the update was actually applied??

    And yes, I know I need to use bind variables but I'm switching to Oracle in a few months and I'll do it once that happens.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  2. #2

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945

    Re: Update result value?

    Nevermind, I got the result. There is a 'mssql_rows_affected' function that returns the number of rows affected by the last result.

    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [RESOLVED] Update result value?

    In all of my tables I have UPDATED_ON and UPDATED_BY fields. Each of my UPDATE/INSERT queries include those two fields so I not only know when that last time the record was updated, but I also know who did the updating (I grab the windows logon id)

    Just a thought...

  4. #4

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945

    Re: [RESOLVED] Update result value?

    Well considering that I refuse to force my users to use IE and I wouldn't dream of using .NET, I'm fine with pulling that info out of a LDAP table based on the login that they use.

    Plus, you're also limiting your users to connecting to your application from a Windows, company-specific workstation. That's kind of a crappy way to handle things, IMHO.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width