12 Replies Latest reply on Sep 5, 2009 9:50 AM by loquela

    using  mysql_insert_id() wwith the ADDT

    Level 1
      can anyone tell me if the use of $id=mysql_insert_id(); is provided for someplace in ADDT or is there another way to know what the auto_increment field value was of the last inserted record.
        • 1. Re: using  mysql_insert_id() wwith the ADDT
          Günter Schenk Level 4
          Hi Dave,

          don´t know if this answers your question, but one of ADDT´s internal functions is named "Insert_ID", which gets the auto-generated inserted id by returning the mysql_insert_id

          -----
          know what the auto_increment field value was of the last inserted record
          -----

          $tNG->getPrimaryKeyValue()

          Some more info in the thread "Pass Inserted ID on redirect": http://www.adobeforums.com/webx/.59b4cde6/1

          Cheers,
          Günter Schenk
          Adobe Community Expert, Dreamweaver
          • 2. Re: using  mysql_insert_id() wwith the ADDT
            Level 1
            Thanks Günter,
            I am using the Insert Into Two Tables Wizard and want to insert a value from the form that is inserted into the first table into the second table but I do not understand how to control the sequence of the events so that the second table is inserted first and the value received from the $tNG->getPrimaryKeyValue() can be inserted with the first table. Is there a way to see the sequence of events?
            • 3. Re: using  mysql_insert_id() wwith the ADDT
              Level 1
              You look at the Trigger type and Trigger priority on registerTrigger() calls to see their order. At this point I am uncertain of the exact relationship between the two parameters.
              • 4. Re: using  mysql_insert_id() wwith the ADDT
                loquela Level 1

                Hi Gunter,

                Could you explain how to use this as I am gettimng the following error:

                Fatal error:  Call to a member function getPrimaryKeyValue() on a non-object in C:\xampp\htdocs\playpics\public_html\admin\add_image.php on line 238

                 

                Thanks in advance,

                • 5. Re: using  mysql_insert_id() wwith the ADDT
                  Günter Schenk Level 4

                  loquela wrote:

                   

                  Hi Gunter,

                  Could you explain how to use this as I am gettimng the following error:

                  Fatal error:  Call to a member function getPrimaryKeyValue() on a non-object...

                  $tNG->getPrimaryKeyValue() appears to be something which only works when used within a Custom Trigger.

                   

                  Cheers,

                  Günter

                  • 6. Re: using  mysql_insert_id() wwith the ADDT
                    loquela Level 1

                    Thanks Gunter, but I'm afraid I am no clearer.

                    I have a form that uploads a bunch of images and inserts a record. I need to get the id of that record to use in a subsequent query. How would I go about doing that? Clearly the redirect gets the value from {img_id} this is the valur I want but how do I capture it in a variable that I can use in a subsequent query. Thanks again for your help with this. S.

                     

                    $ins_pp_images->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Insert1");
                    $ins_pp_images->registerTrigger("END", "Trigger_Default_Redirect", 99, "edit_image.php?img_id={img_id}");
                    $ins_pp_images->registerTrigger("AFTER", "Trigger_ImageUpload", 97);
                    $ins_pp_images->registerTrigger("AFTER", "Trigger_ImageUpload1", 97);
                    $ins_pp_images->registerTrigger("AFTER", "Trigger_ImageUpload2", 97);
                    $ins_pp_images->registerTrigger("AFTER", "Trigger_ImageUpload3", 97);
                    $ins_pp_images->registerTrigger("AFTER", "Trigger_ImageUpload4", 97);
                    $ins_pp_images->registerTrigger("AFTER", "Trigger_ImageUpload5", 97);
                    $ins_pp_images->registerTrigger("AFTER", "Trigger_ImageUpload6", 97);
                    $ins_pp_images->registerTrigger("AFTER", "Trigger_ImageUpload7", 97);
                    // Add columns
                    $ins_pp_images->setTable("pp_images");
                    $ins_pp_images->addColumn("img_name", "STRING_TYPE", "POST", "img_name");
                    $ins_pp_images->addColumn("img_type", "NUMERIC_TYPE", "POST", "img_type");
                    $ins_pp_images->addColumn("img_keywords", "STRING_TYPE", "POST", "img_keywords");
                    $ins_pp_images->addColumn("img_description", "STRING_TYPE", "POST", "img_description");
                    $ins_pp_images->addColumn("img_jpeg", "FILE_TYPE", "FILES", "img_jpeg");
                    $ins_pp_images->addColumn("img_jpeg_bw", "FILE_TYPE", "FILES", "img_jpeg_bw");
                    $ins_pp_images->addColumn("img_wmf", "FILE_TYPE", "FILES", "img_wmf");
                    $ins_pp_images->addColumn("img_wmf_bw", "FILE_TYPE", "FILES", "img_wmf_bw");
                    $ins_pp_images->addColumn("img_eps", "FILE_TYPE", "FILES", "img_eps");
                    $ins_pp_images->addColumn("img_eps_bw", "FILE_TYPE", "FILES", "img_eps_bw");
                    $ins_pp_images->addColumn("img_png", "FILE_TYPE", "FILES", "img_png");
                    $ins_pp_images->addColumn("img_png_bw", "FILE_TYPE", "FILES", "img_png_bw");
                    $ins_pp_images->addColumn("img_uploaded", "STRING_TYPE", "POST", "img_uploaded");
                    $ins_pp_images->addColumn("img_downloads", "NUMERIC_TYPE", "POST", "img_downloads");
                    $ins_pp_images->addColumn("subscription", "CHECKBOX_YN_TYPE", "POST", "subscription");
                    $ins_pp_images->addColumn("active", "CHECKBOX_YN_TYPE", "POST", "active");
                    $ins_pp_images->setPrimaryKey("img_id", "NUMERIC_TYPE");

                    • 7. Re: using  mysql_insert_id() wwith the ADDT
                      Günter Schenk Level 4

                      We recently had a very interesting discussion in the ADDT General Discussion thread I want the result page of my insert form to be an update form of the just inserted data.

                       

                      In your case I also think that assigning the "$tNG->GetPrimaryKeyValue()" - value to a custom Session Variable (within the scope of a Custom Trigger of course) and later on use this Session Variable in a subsequent query should do the trick.

                       

                      Cheers,

                      Günter

                      • 8. Re: using  mysql_insert_id() wwith the ADDT
                        loquela Level 1

                        Thanks Gunter,

                         

                        There is no problem using the value in the edit page to which the use is redirected after the insert as that is taken care of here $ins_pp_images->registerTrigger("END", "Trigger_Default_Redirect", 99, "edit_image.php?img_id={img_id}");

                         

                        What I need is something like

                         

                        $nextimageid = $tNG->GetPrimaryKeyValue() +1

                         

                        as I want to use $nextimageid in a separate insert query that takes place before the redirect. Unfortunately this doesn't work.

                         

                        As always, many thanks for your help.

                        • 9. Re: using  mysql_insert_id() wwith the ADDT
                          Günter Schenk Level 4

                          loquela wrote:

                           

                          What I need is something like

                           

                          $nextimageid = $tNG->GetPrimaryKeyValue() +1

                           

                          as I want to use $nextimageid in a separate insert query that takes place before the redirect.

                          how about encsapulating the following in a Custom [AFTER, but "placed" (aka "priority") before the separate insert query] Trigger:

                           

                          $_SESSION['nextimageid'] = $tNG->GetPrimaryKeyValue() +1;

                           

                          ...and use $_SESSION['nextimageid'] as Primary Key value in the secondary query ?

                           

                          Cheers,

                          Günter

                          • 10. Re: using  mysql_insert_id() wwith the ADDT
                            loquela Level 1

                            Thanks again Gunter, please bear with me on this.

                             

                            I'm not used to using custom triggers so I need it spelling out. Also I 'm not sure I've made my requirement clear.

                            I just want to get the next auto increment from the last insert transaction. The value will be used on a query on the same page as the insert so I'm sure why  a session variable is needed?

                             

                            I appreciate you patience.

                            • 11. Re: using  mysql_insert_id() wwith the ADDT
                              Günter Schenk Level 4

                              loquela wrote:

                               

                              I'm not used to using custom triggers so I need it spelling out.

                              please bear with me too

                               

                              1. as it seems technically impossible to use ADDT´s $tNG->getPrimaryKeyValue() "placeholder" outside a Custom Trigger, it´s crucial to know how ADDT´s Custom Triggers work, and although the help file is admittedly not the best one on earth, it does provide quite some useful information on Custom Triggers respectively how it´s possible to tell ADDT to execute the custom PHP code within a Custom Trigger e.g. after the main insert transaction, but preceeding the secondary transaction -- and this is what you can adjust by defining the so-called "priority" order of the various transactions you already have in place *including* the Custom Trigger which can be assigned an arbitrary "priority" value as well.

                               

                              2. the only thing I think I can "spell out" is suggesting to copy/paste the previously provided sample code into the textarea of an ADDT Custom Trigger server behaviour instance and see if this works

                               

                              Also I 'm not sure I've made my requirement clear.

                              I fully understand what you want to achieve :-)

                               

                              I just want to get the next auto increment from the last insert transaction.

                              $tNG->getPrimaryKeyValue()

                               

                              The value will be used on a query on the same page as the insert so I'm sure why a session variable is needed?

                               

                              Unlike a standard PHP variable ($whatever) a Session Variable has the advantage of being "global", means that once it´s become initialized within a page (or in your case, within a Custom Trigger), its assigned value [$tNG->getPrimaryKeyValue()] will be reusable rightaway in various other "places" (e.g. within other functions) without further ado, what can´t be taken for granted when using regular PHP variables.

                               

                              Cheers,

                              Günter

                              • 12. Re: using  mysql_insert_id() wwith the ADDT
                                loquela Level 1

                                Gunter, I owe you one.


                                You've done it again!

                                 

                                Many thanks indeed.

                                 

                                S.