8 Replies Latest reply on Mar 24, 2009 1:18 PM by Günter Schenk

    update record using a recordset withOUT hitting a submit button

      I guess what I'm asking is there a way to Update a record, without having to click a submit button?

      Can I enter data into an Insert form, on the next page, call that recordset and update the same record and then auto-redirect to a 3rd page?

      What I'm trying to is this. I have one table column that is the calculation of two other columns: column1 * column2. I haven't figured out how to do this on one page, so I'm breaking it up into 2 pages. I've got the calculation working on the second page but what I'm trying to do is:
      ---input the 2 values on the input form on page1
      ---on page two, you never see. the calculation is made and the page auto redirects to the next page that says thanks.

      I've changed the register trigger to this below but it hasn't worked.

      Any help would be appreciated.

      $upd_test_tes->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "VALUE", "1");

      Thanks!

      Peter T
        • 1. Re: update record using a recordset withOUT hitting a submit button
          Günter Schenk Level 4
          Hi Peter,

          there are several ways to achieve this, however if you´re already somewhat familiar with how ADDT´s Custom Triggers work, you could even do this on the very same page by...

          a) calculating the two transaction values and assign the result to a PHP variable

          b) update the respective column which "belongs" to the current table´s Primary Key value while use this PHP variable as the to-be-updated value

          All this would have to be defined in Custom "after" Trigger.

          BTW, may I ask why exactly you´re planning to store the calculated value in the table rather than simply displaying the calculated result of two recordset values "on the fly" in the very document which needs this?

          Cheers
          Günter Schenk
          Adobe Community Expert, Dreamweaver
          • 2. Re: update record using a recordset withOUT hitting a submit button
            Level 1
            Thanks Günter!
            I'll give this a try.

            The reason is because this project is for a case study model and two of the database columns are calculations of other table columns. Once the data is in the database, they will be able to sort this as well as all the other information using ADDT's filters...which are excellent!

            I'm also adding it to the db just in case they want to export the data to excel or another file type and the calculations will already be there.
            • 3. Re: update record using a recordset withOUT hitting a submit button
              Level 1
              I'm so close but still looking for help.

              Below is my code. For some reason, the calculation is working, yet the total that is entered into the database row is for the previous entry.

              For instance, I'll enter a 3 in one table column and a 2 in the other, the first time I click submit, in the database will be a NULL in the 'total'column. The next time I enter a 5 in one column and a 6 in the other, I get the total for the previous entry, which would be 6.

              Any idea what I'm missing?

              Thanks in advance!
              Peter T


              //start Trigger_Custom trigger
              function Trigger_Custom(&$tNG) {
              $_SESSION['id_tes'] = $tNG->getPrimaryKeyValue();
              $_SESSION['total'] = $_POST['rate_tes'] * $_POST['duration_tes'];
              }
              //end Trigger_Custom trigger

              // Make an insert transaction instance
              $ins_test_tes = new tNG_insert($conn_dispute_resolution);
              $tNGs->addTransaction($ins_test_tes);
              // Register triggers
              $ins_test_tes->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Insert1");
              $ins_test_tes->registerTrigger("BEFORE", "Trigger_Default_FormValidation", 10, $formValidation);
              $ins_test_tes->registerTrigger("END", "Trigger_Default_Redirect", 99, "index.php?id_tes={SESSION.id_tes}");
              $ins_test_tes->registerTrigger("BEFORE", "Trigger_Custom", 50);
              // Add columns
              $ins_test_tes->setTable("test_tes");
              $ins_test_tes->addColumn("rate_tes", "NUMERIC_TYPE", "POST", "rate_tes");
              $ins_test_tes->addColumn("duration_tes", "NUMERIC_TYPE", "POST", "duration_tes");
              $ins_test_tes->addColumn("total_tes", "DOUBLE_TYPE", "VALUE", "{SESSION.total}");
              $ins_test_tes->setPrimaryKey("id_tes", "NUMERIC_TYPE");
              • 4. Re: update record using a recordset withOUT hitting a submit button
                Günter Schenk Level 4
                Hi Peter,

                I suggest doing it a different way -- what I meant is using the calculated transaction values within the context of an UPDATE query inside a Custom "after" Trigger.

                For a start you might want to have a look at ADDT´s help file. Please see "Custom transactions and triggers" -> "Use transaction fields" -- in here you´ll find a PHP example for a somwhat similar UPDATE query which basically just requires an adaption of the query that´s assigned to the initial $query variable.

                Cheers,
                Günter Schenk
                Adobe Community Expert, Dreamweaver
                • 5. Re: update record using a recordset withOUT hitting a submit button
                  Level 1
                  Thanks for the tip Gunter.
                  I'm so close!
                  I'm getting the following error.

                  Fatal error: Call to undefined function getPrimaryKeyValue() in /home/httpd/html/modr/programs/ag_med/test.php on line 28

                  Here's my code, I've marked line 28

                  //start Trigger_Custom trigger
                  function Trigger_Custom(&$tNG) {
                  $_SESSION['id_tes'] = $tNG->getPrimaryKeyValue();
                  $_SESSION['total'] = $_POST['rate_tes'] * $_POST['duration_tes'];
                  $total = $_SESSION['total'];
                  //Line 28//$query = "UPDATE test_tes SET id_tes = ".KT_escapeForSql($tNG>getPrimaryKeyValue(),
                  $tNG->getColumnType($tNG>getPrimaryKey()))." WHERE id_tes = ".$tNG>getPrimaryKeyValue();
                  $update_result = $tNG->connection>execute($query);
                  if($tNG->getColumnValue("total_tes") == "0") {
                  $tNG->setColumnValue("total_tes",$total);
                  }
                  }
                  //end Trigger_Custom trigger

                  Am I setting the Primary Key twice and therefore is it canceling out?
                  My goal is to update the total_tes column in the test_table with the variable $total, which is the calculation/multiplication variable.

                  Thanks!

                  Peter T
                  • 6. Re: update record using a recordset withOUT hitting a submit button
                    Günter Schenk Level 4
                    Hi Peter,

                    -------
                    Am I setting the Primary Key twice and therefore is it canceling out?
                    -------

                    I don´t think so, because you´re actually not using the Session Variable $_SESSION['id_tes'] in the Update query. Please check if the tNG classes are loaded:

                    // Load the tNG classes
                    require_once('../../includes/tng/tNG.inc.php');

                    ------
                    $query = "UPDATE test_tes SET id_tes = ".KT_escapeForSql($tNG>getPrimaryKeyValue(),
                    $tNG->getColumnType($tNG>getPrimaryKey()))." WHERE id_tes = ".$tNG>getPrimaryKeyValue();
                    ------

                    this would set the Primary Key column to the current Primary Key, what doesn´t make sense -- you´ll just need to set the "total_tes" column to the value of the variable $total

                    ------
                    $_POST['rate_tes'] * $_POST['duration_tes'];
                    ------

                    ADDT´s Custom Triggers use transaction value in a different way, and the general syntax is:
                    $tNG->getColumnValue("column_name")

                    In conjunction with streamlining the code and doing away with the superflous Session declarations I suggest trying this:

                    $rate_tes = $tNG->getColumnValue("rate_tes");
                    $duration_tes = $tNG->getColumnValue("duration_tes");

                    $total = $rate_test * $duration_tes;

                    Cheers,
                    Günter Schenk
                    Adobe Community Expert, Dreamweaver
                    • 7. Re: update record using a recordset withOUT hitting a submit button
                      Level 1
                      THANKS Günter!!!!!!!!!!!!!!!!!!!!!!!!!

                      It's working!!!

                      Ironically, 80% of my problem (once you helped me fix the code) was this:
                      $tNG->getColumnValue
                      $tNG->connection->execute($query);

                      When I copied them in from the samples onto my page they copied like this:
                      $tNG>getColumnValue
                      $tNG>connection->execute($query);

                      who new the dash between the tNG and the > would make such a difference! Thanks for your help!!!
                      • 8. Re: update record using a recordset withOUT hitting a submit button
                        Günter Schenk Level 4
                        Yay ! :-)

                        Cheers,
                        Günter Schenk
                        Adobe Community Expert, Dreamweaver