1 2 Previous Next 15 Replies Latest reply on Nov 15, 2014 8:11 AM by ebisu

    Trouble in Editing data via PHP CWP

    ebisu

      A simple database, "NWeb.fmp12" with a layout "Program Detail", where there is a field "title". The only purpose is to edit this field via PHP.

      I made a bunch of php pages, such as doing compound find and jumping to detail from the list.

      (like: search.php→ result.php→ detail.php→ edit.php→ receive.php)

      Until "edit.php", it was perfect. But "edit.php→ receive.php" does not work well。

      Here are the codes。

       

      1、edit.php

      <?php

      header("Content-Type: text/html; charset = utf-8");

      ini_set('display_error',1);

      require_once('FileMaker.php');

      $fm = new FileMaker('NWeb','localhost','web','pass');

      $record = $fm->getRecordById('Program Detail',$_POST['recid']);

      ?>

      <!doctype html>

      <html>

      <head>

      <meta charset = "utf-8">

      <title>Edit</title>

      </head>

      <body>

      <form action="receive.php" method="post">

      <table>

      <tr>

      <th>Title</th>

      <td><input type="text" name="title" value="<?=$record->getField('title')?>"></td>

      </tr>

      <input type="hidden" name="recid" value="<?=$_POST['recid']?>">

      <input type="submit" value="Save">

      <!-- "recid" is passed from the former page by a form with the hidden method --!>

      </table>

      </form>

      </body>

      </html>

       

      2、receive.php

      <?php

      header("Content-Type: text/html; charset = utf-8");

      ini_set('display_error',1);

      require_once('FileMaker.php');

      $fm = new FileMaker('NWeb','localhost','web','pass');

      $edit = $fm->newEditCommand('Program Detail', $_POST['recid']);

      $edit -> setField('title', $_POST['title']);

      $result = $edit->execute();

      echo $_POST['recid'] . $_POST['title'];

      ?>

      <!doctype html>

      <html>

      <head>

      <meta charset = "utf-8">

      <title>Saved</title>

      </head>

      <body>Saved</body>

      </html>

       

      I updated "Title" field on edit.php and click "Save" button, and the page turned to receive.php.

      By the statement echo $_POST['recid'] . $_POST['title']; the value of Title I updated was shown. (also shows Saved by <html>)

      So I think the data were passed successfully between php pages.

      But in FileMaker, data weren't ever been changed, even if I'd been trying other methods like "commit( )" on the red php codes above.

       

      I appreciate anyone who can help me!

        • 1. Re: Trouble in Editing data via PHP CWP
          TimDietrich

          Hi there.

           

          You might want to try adding some code (after the "$result = $edit->execute();" line) to see if FileMaker is throwing an error, like this:

           

          if (FileMaker::isError( $result )) {

               echo "Error Code: " . $result->code . "<br>";

               echo "Error Message: " . $result->getMessage() . "<br>";

               die;

          }

           

          Another option is to dump the entire result out to see what it looks like. For example:

           

          echo '<pre>';

          var_dump ( $result );

          die;

           

          -- Tim

          • 2. Re: Trouble in Editing data via PHP CWP
            LyndsayHowarth

            Are you sure your user has the right privileges and have PHP turned on in extended privileges?

             

            - Lyndsay

            1 of 1 people found this helpful
            • 3. Re: Trouble in Editing data via PHP CWP
              LyndsayHowarth

              Also check the fields and layout names are exactly the same in the database... and it is case sensitive.

               

              - Lyndsay

              • 4. Re: Trouble in Editing data via PHP CWP
                ebisu

                Thank you, Tim.

                 

                I checked errcode. FileMaker Error 1 : User canceled action

                 

                And I dump the result as you suggested. Below is the output. I am not sure what it means.

                ----------

                object(FileMaker_Error)#62 (9) {

                  ["_fm"]=>

                  &object(FileMaker_Implementation)#2 (3) {

                    ["V73ee434e"]=>

                    array(9) {

                      ["charset"]=>

                      string(5) "UTF-8"

                      ["locale"]=>

                      string(2) "ja"

                      ["logLevel"]=>

                      int(3)

                      ["hostspec"]=>

                      string(9) "localhost"

                      ["recordClass"]=>

                      string(16) "FileMaker_Record"

                      ["prevalidate"]=>

                      bool(false)

                      ["database"]=>

                      string(7) "NWeb"

                      ["username"]=>

                      string(3) "web"

                      ["password"]=>

                      string(4) "pass"

                    }

                    ["Vea4b3413"]=>

                    NULL

                    ["V9a3dcbce"]=>

                    NULL

                  }

                  ["error_message_prefix"]=>

                  string(0) ""

                  ["mode"]=>

                  int(1)

                  ["level"]=>

                  int(1024)

                  ["code"]=>

                  string(1) "6"

                  ["message"]=>

                  NULL

                  ["userinfo"]=>

                  NULL

                  ["backtrace"]=>

                  array(6) {

                    [0]=>

                    array(6) {

                      ["file"]=>

                      string(100) "/Library/FileMaker Server/Web Publishing/publishing-engine/php/mavericks/lib/php/FileMaker/Error.php"

                      ["line"]=>

                      int(52)

                      ["function"]=>

                      string(10) "PEAR_Error"

                      ["class"]=>

                      string(10) "PEAR_Error"

                      ["type"]=>

                      string(2) "->"

                      ["args"]=>

                      array(2) {

                        [0]=>

                        NULL

                        [1]=>

                        string(1) "6"

                      }

                    }

                    [1]=>

                    array(7) {

                      ["file"]=>

                      string(128) "/Library/FileMaker Server/Web Publishing/publishing-engine/php/mavericks/lib/php/FileMaker/Implementation/Parser/FMResultSet.php"

                      ["line"]=>

                      int(48)

                      ["function"]=>

                      string(15) "FileMaker_Error"

                      ["class"]=>

                      string(15) "FileMaker_Error"

                      ["object"]=>

                      *RECURSION*

                      ["type"]=>

                      string(2) "->"

                      ["args"]=>

                      array(3) {

                        [0]=>

                        &object(FileMaker_Implementation)#2 (3) {

                          ["V73ee434e"]=>

                          array(9) {

                            ["charset"]=>

                            string(5) "UTF-8"

                            ["locale"]=>

                            string(2) "ja"

                            ["logLevel"]=>

                            int(3)

                            ["hostspec"]=>

                            string(9) "localhost"

                            ["recordClass"]=>

                            string(16) "FileMaker_Record"

                            ["prevalidate"]=>

                            bool(false)

                            ["database"]=>

                            string(7) "NWeb"

                            ["username"]=>

                            string(3) "web"

                            ["password"]=>

                            string(4) "pass"

                          }

                          ["Vea4b3413"]=>

                          NULL

                          ["V9a3dcbce"]=>

                          NULL

                        }

                        [1]=>

                        NULL

                        [2]=>

                        string(1) "6"

                      }

                    }

                    [2]=>

                    array(7) {

                      ["file"]=>

                      string(121) "/Library/FileMaker Server/Web Publishing/publishing-engine/php/mavericks/lib/php/FileMaker/Implementation/CommandImpl.php"

                      ["line"]=>

                      int(84)

                      ["function"]=>

                      string(5) "parse"

                      ["class"]=>

                      string(28) "FileMaker_Parser_FMResultSet"

                      ["object"]=>

                      object(FileMaker_Parser_FMResultSet)#5 (17) {

                        ["Vcb5e100e"]=>

                        string(1) "6"

                        ["Vf5bf48aa"]=>

                        array(3) {

                          ["build"]=>

                          string(10) "04/20/2014"

                          ["name"]=>

                          string(31) "FileMaker Web Publishing Engine"

                          ["version"]=>

                          string(10) "13.0.2.296"

                        }

                        ["V1ea7e575"]=>

                        array(7) {

                          ["database"]=>

                          string(0) ""

                          ["date-format"]=>

                          string(0) ""

                          ["layout"]=>

                          string(0) ""

                          ["table"]=>

                          string(0) ""

                          ["time-format"]=>

                          string(0) ""

                          ["timestamp-format"]=>

                          string(0) ""

                          ["total-count"]=>

                          string(1) "0"

                        }

                        ["V9f81f3c0"]=>

                        array(0) {

                        }

                        ["Vaae0d98d"]=>

                        array(2) {

                          ["count"]=>

                          string(1) "0"

                          ["fetch-size"]=>

                          string(1) "0"

                        }

                        ["Vae581270"]=>

                        array(0) {

                        }

                        ["V6e52c40b"]=>

                        array(0) {

                        }

                        ["Ve13f1c92"]=>

                        NULL

                        ["V43432a31"]=>

                        NULL

                        ["V51bc3e3b"]=>

                        NULL

                        ["V26005321"]=>

                        NULL

                        ["V6468d939"]=>

                        NULL

                        ["_fm"]=>

                        &object(FileMaker_Implementation)#2 (3) {

                          ["V73ee434e"]=>

                          array(9) {

                            ["charset"]=>

                            string(5) "UTF-8"

                            ["locale"]=>

                            string(2) "ja"

                            ["logLevel"]=>

                            int(3)

                            ["hostspec"]=>

                            string(9) "localhost"

                            ["recordClass"]=>

                            string(16) "FileMaker_Record"

                            ["prevalidate"]=>

                            bool(false)

                            ["database"]=>

                            string(7) "NWeb"

                            ["username"]=>

                            string(3) "web"

                            ["password"]=>

                            string(4) "pass"

                          }

                          ["Vea4b3413"]=>

                          NULL

                          ["V9a3dcbce"]=>

                          NULL

                        }

                        ["V5431b8d4"]=>

                        resource(28) of type (Unknown)

                        ["V6de51026"]=>

                        bool(false)

                        ["_result"]=>

                        NULL

                        ["_layout"]=>

                        NULL

                      }

                      ["type"]=>

                      string(2) "->"

                      ["args"]=>

                      array(1) {

                        [0]=>

                        string(564) ""

                      }

                    }

                    [3]=>

                    array(7) {

                      ["file"]=>

                      string(126) "/Library/FileMaker Server/Web Publishing/publishing-engine/php/mavericks/lib/php/FileMaker/Implementation/Command/EditImpl.php"

                      ["line"]=>

                      int(76)

                      ["function"]=>

                      string(10) "_getResult"

                      ["class"]=>

                      string(32) "FileMaker_Command_Implementation"

                      ["object"]=>

                      object(FileMaker_Command_Edit_Implementation)#4 (14) {

                        ["_fields"]=>

                        array(1) {

                          ["title"]=>

                          array(1) {

                            [0]=>

                            string(69) "Updated value"

                          }

                        }

                        ["_modificationId"]=>

                        NULL

                        ["V6d6e1fd2"]=>

                        NULL

                        ["_fm"]=>

                        &object(FileMaker_Implementation)#2 (3) {

                          ["V73ee434e"]=>

                          array(9) {

                            ["charset"]=>

                            string(5) "UTF-8"

                            ["locale"]=>

                            string(2) "ja"

                            ["logLevel"]=>

                            int(3)

                            ["hostspec"]=>

                            string(9) "localhost"

                            ["recordClass"]=>

                            string(16) "FileMaker_Record"

                            ["prevalidate"]=>

                            bool(false)

                            ["database"]=>

                            string(7) "NWeb"

                            ["username"]=>

                            string(3) "web"

                            ["password"]=>

                            string(4) "pass"

                          }

                          ["Vea4b3413"]=>

                          NULL

                          ["V9a3dcbce"]=>

                          NULL

                        }

                        ["_layout"]=>

                        string(14) "Program Detail"

                        ["V7a2db0ea"]=>

                        NULL

                        ["_script"]=>

                        NULL

                        ["_scriptParams"]=>

                        NULL

                        ["_preReqScript"]=>

                        NULL

                        ["_preReqScriptParams"]=>

                        NULL

                        ["_preSortScript"]=>

                        NULL

                        ["_preSortScriptParams"]=>

                        NULL

                        ["V0b9a204c"]=>

                        string(16) "FileMaker_Record"

                        ["_recordId"]=>

                        string(1) "9"

                      }

                      ["type"]=>

                      string(2) "->"

                      ["args"]=>

                      array(1) {

                        [0]=>

                        string(564) ""

                      }

                    }

                    [4]=>

                    array(7) {

                      ["file"]=>

                      string(102) "/Library/FileMaker Server/Web Publishing/publishing-engine/php/mavericks/lib/php/FileMaker/Command.php"

                      ["line"]=>

                      int(137)

                      ["function"]=>

                      string(7) "execute"

                      ["class"]=>

                      string(37) "FileMaker_Command_Edit_Implementation"

                      ["object"]=>

                      object(FileMaker_Command_Edit_Implementation)#4 (14) {

                        ["_fields"]=>

                        array(1) {

                          ["title"]=>

                          array(1) {

                            [0]=>

                            string(69) "Updated value"

                          }

                        }

                        ["_modificationId"]=>

                        NULL

                        ["V6d6e1fd2"]=>

                        NULL

                        ["_fm"]=>

                        &object(FileMaker_Implementation)#2 (3) {

                          ["V73ee434e"]=>

                          array(9) {

                            ["charset"]=>

                            string(5) "UTF-8"

                            ["locale"]=>

                            string(2) "ja"

                            ["logLevel"]=>

                            int(3)

                            ["hostspec"]=>

                            string(9) "localhost"

                            ["recordClass"]=>

                            string(16) "FileMaker_Record"

                            ["prevalidate"]=>

                            bool(false)

                            ["database"]=>

                            string(7) "NWeb"

                            ["username"]=>

                            string(3) "web"

                            ["password"]=>

                            string(4) "pass"

                          }

                          ["Vea4b3413"]=>

                          NULL

                          ["V9a3dcbce"]=>

                          NULL

                        }

                        ["_layout"]=>

                        string(14) "Program Detail"

                        ["V7a2db0ea"]=>

                        NULL

                        ["_script"]=>

                        NULL

                        ["_scriptParams"]=>

                        NULL

                        ["_preReqScript"]=>

                        NULL

                        ["_preReqScriptParams"]=>

                        NULL

                        ["_preSortScript"]=>

                        NULL

                        ["_preSortScriptParams"]=>

                        NULL

                        ["V0b9a204c"]=>

                        string(16) "FileMaker_Record"

                        ["_recordId"]=>

                        string(1) "9"

                      }

                      ["type"]=>

                      string(2) "->"

                      ["args"]=>

                      array(0) {

                      }

                    }

                    [5]=>

                    array(7) {

                      ["file"]=>

                      string(94) "/Library/FileMaker Server/Web Publishing/web-server-support/test/fmi-test/testrong/receive.php"

                      ["line"]=>

                      int(23)

                      ["function"]=>

                      string(7) "execute"

                      ["class"]=>

                      string(17) "FileMaker_Command"

                      ["object"]=>

                      object(FileMaker_Command_Edit)#3 (1) {

                        ["_impl"]=>

                        object(FileMaker_Command_Edit_Implementation)#4 (14) {

                          ["_fields"]=>

                          array(1) {

                            ["title"]=>

                            array(1) {

                              [0]=>

                              string(69) "Updated value"

                            }

                          }

                          ["_modificationId"]=>

                          NULL

                          ["V6d6e1fd2"]=>

                          NULL

                          ["_fm"]=>

                          &object(FileMaker_Implementation)#2 (3) {

                            ["V73ee434e"]=>

                            array(9) {

                              ["charset"]=>

                              string(5) "UTF-8"

                              ["locale"]=>

                              string(2) "ja"

                              ["logLevel"]=>

                              int(3)

                              ["hostspec"]=>

                              string(9) "localhost"

                              ["recordClass"]=>

                              string(16) "FileMaker_Record"

                              ["prevalidate"]=>

                              bool(false)

                              ["database"]=>

                              string(7) "NWeb"

                              ["username"]=>

                              string(3) "web"

                              ["password"]=>

                              string(4) "pass"

                            }

                            ["Vea4b3413"]=>

                            NULL

                            ["V9a3dcbce"]=>

                            NULL

                          }

                          ["_layout"]=>

                          string(14) "Program Detail"

                          ["V7a2db0ea"]=>

                          NULL

                          ["_script"]=>

                          NULL

                          ["_scriptParams"]=>

                          NULL

                          ["_preReqScript"]=>

                          NULL

                          ["_preReqScriptParams"]=>

                          NULL

                          ["_preSortScript"]=>

                          NULL

                          ["_preSortScriptParams"]=>

                          NULL

                          ["V0b9a204c"]=>

                          string(16) "FileMaker_Record"

                          ["_recordId"]=>

                          string(1) "9"

                        }

                      }

                      ["type"]=>

                      string(2) "->"

                      ["args"]=>

                      array(0) {

                      }

                    }

                  }

                  ["callback"]=>

                  NULL

                }

                • 5. Re: Trouble in Editing data via PHP CWP
                  ebisu

                  Thank you, Lyndsay.

                   

                  I checked the names, and they were the same.

                  In extended privileges, PHP is the only option I turned on.

                  Also the privilege allows the user"web" to edit records.

                  • 7. Re: Trouble in Editing data via PHP CWP
                    TimDietrich

                    Actually, based on the dump of the result, it looks like error code 6 is being thrown. That indicates that the "File is read-only."

                     

                    Is it possible that the file was inadvertently set to Read-Only?

                     

                    -- Tim

                    • 8. Re: Trouble in Editing data via PHP CWP
                      ebisu

                      That is a new hint, but why it happened? I can edit the record in FileMaker Pro.

                      Is any cache problem possible?

                      • 9. Re: Trouble in Editing data via PHP CWP
                        TimDietrich

                        That does seem odd. I would think that if the file itself were read only, you would have noticed because any changes made via Pro would fail as well. So perhaps it is a permissions problem that is specific to CWP. If so, I've never run into that.

                         

                        You might want to try creating a new record via the API, and see if you get similar behavior.

                         

                        -- Tim

                        • 10. Re: Trouble in Editing data via PHP CWP
                          ebisu

                          Thanks, Tim. I'll try adding a record later.

                          As I checked the log in FileMaker Server after editing record via API, it showed:

                           

                          ... Error 192.168.1.106 127.0.0.1:54457 web - 6 564 "/fmi/xml/fmresultset.xml?-db=NWeb&-lay=Program Detail&-edit&title(1)=Updated value&-recid=9"

                           

                          I noticed that keyword in red is weird, because fieldname is "title", not "title(1)".

                          I don't know why but I tried changing fieldname to another such as "ntitle", and it came up with a similar err log with"ntitle(1)".

                          • 11. Re: Trouble in Editing data via PHP CWP
                            TimDietrich

                            The "(1)" is the repetition number. While this isn't a repeating field, the API assumes that it is, and this is its way of indicating the specific repetition being updated.

                             

                            -- Tim

                            1 of 1 people found this helpful
                            • 12. Re: Trouble in Editing data via PHP CWP
                              ebisu

                              I tried adding a new record via API, but failed in Pro, just as you assumed. I can't write via API.

                              • 13. Re: Trouble in Editing data via PHP CWP
                                TimDietrich

                                It sounds like the file really is read-only.

                                 

                                You might want to take it offline and look at it.

                                 

                                -- Tim

                                • 14. Re: Trouble in Editing data via PHP CWP
                                  ebisu

                                  I can do any editing in Pro with the same account. Really weird.

                                  Does it mean I haven't set the API or php correctly?

                                  1 2 Previous Next