4 Replies Latest reply on Jan 4, 2010 3:14 AM by Craig_Paterson

    Insert "NULL" when no image uploaded with ADDT

    Craig_Paterson

      Hi all,

       

      I have built a system in PHP/MySQL for a client where they can upload an image using ADDT and it works great apart from one thing...

       

      I have tried everything I can think of to insert NULL into the database field which stores the uploaded filename if no image is uploaded (uploading an image is not required). When the form is submitted without a file upload, the database field is always blank, but I need it to be NULL.

       

      The default value of the database field is NULL

      I have tried attaching "value = 'NULL'" to the file field

       

      Any help on this would be greatly appreciated

       

       

       

      Craig

        • 1. Re: Insert "NULL" when no image uploaded with ADDT
          Günter Schenk Level 4

          Off the top of my head I´d suggest to...

           

          1. establish a Custom Trigger, type: AFTER

           

          2. in here define a standard SQL UPDATE statement like this:

           

          UPDATE tablename SET filefield_column = 'NULL' WHERE primarykey_colum = [make it equal the current record´s Primary Key value]

           

          3. ...and make sure that this Custom Trigger will only be put in execution when the Transaction Value representing the form´s file field is *not* empty

           

          Cheers,

          Günter

          • 2. Re: Insert "NULL" when no image uploaded with ADDT
            Craig_Paterson Level 1

            Hi Günter,

             

            Many thanks for your response, although I must admit, I am struggling a bit with the final part of your solution, as I have never used Custom Triggers before.

             

            In part 3, how do I go about checking that the Custom Trigger is only executed when the Insert Transaction's File Field is *not* empty?

             

            Is there any way you could possibly expand on this a bit please, I really can't see where this would be added to make it work.

             

            Kind regards,

             

            Craig

            • 3. Re: Insert "NULL" when no image uploaded with ADDT
              Günter Schenk Level 4

              Hi Craig,

               

              sorry for the delayed reply -- hey, it´s christmas time ;-)

               

              cp:fusion wrote:

               

              I am struggling a bit with the final part of your solution, as I have never used Custom Triggers before.

              The ADDT help file provides some Custom Trigger examples, and for a start I recommend playing with the "For PHP" example under "Custom transactions and triggers -> Use transaction fields", which not just gives you a basic code skeleton, but also introduces one important key element you´ll need for your custom Update query as well:

               

              KT_escapeForSql($tNG->getPrimaryKeyValue(), $tNG->getColumnType($tNG->getPrimaryKey()))

               

              ...which represents the Primary Key value of the previously inserted record.

               

              how do I go about checking that the Custom Trigger is only executed when the Insert Transaction's File Field is *not* empty?

              you could try with wrapping the complete Custom Trigger code (but not the Trigger function itself !) in a standard PHP "if" construct which checks whether the file field´s value is not empty:

               

              if ($tNG->getColumnValue("column_name") != '') {

              trigger code here...

              }

               

              Cheers,

              Günter

              1 person found this helpful
              • 4. Re: Insert "NULL" when no image uploaded with ADDT
                Craig_Paterson Level 1

                Hi Günter, Happy New Year,

                 

                Indeed it was Christmas and New Year, so I apologise for the delay in getting back to you too.

                 

                Many, many thanks for your detailed help and supplied code. They have been extremely helpful in getting to know how to use Custom Triggers.

                 

                I would like to commend you on your help on these forums, very much appreciated.

                 

                Kind regards,

                 

                Craig