3 Replies Latest reply on Dec 12, 2012 10:08 AM by artdezign

    Delete Record Detail not working

    artdezign

      Hi,

       

      I find the people on this forum are exceptionally helpful. I've been learning FileMaker API and PHP from the "Filemaker API for PHP" book by Todd Duell, and using his example code I have been unable to get my delete record detail function to work. My delete form file seems to be working, but once the POST is sent to the detail page it just comes up blank, like the php code is bad. Could you take a look and give me suggestions? Oh world of wonderful developers...

       

      detail code:

       

       

       

       

       

      <?php

      include ("dbaccess.php");

      ?>

       

       

      <?php

      # Start by getting the record by the RecordID (id) passed in the URL.

      # Store it in the $record variable.

      # Syntax: $record = $fm->getrecordByID("LayoutName", RecordID)

      # You can use either the $_GET or $_REQUEST superglobal to retrive the id value from the URL.

       

      $record = $fm->getRecordByID("BlogPosts", $_GET['id']);

      ?>

       

       

      <?php

      # check the POST array to see what action to take

      # When the page is loaded show the fields and buttons.

      # By using !isset() the fields and form won't display after the user clicks the Delete or Cancel buttons.

      # This is critical because after the record is deleted the page will load the very first record in the found set.

      # This could confuse the user because they could delete another record. The problem is that no id value exists in the URL.

      # This is a very bad scenario. So it's better to not display anything and only give a link back to the list view page.

       

      if (!isset($_POST['delete']))

      {

       

      # Create the html in the $display variable to ask the user if they want to delete the record.

      $display = 'Are you sure you want to delete record: '.$record->getField('title').'?';

      $display .= '<form action="delete_record_detail.php" method="post">';

      $display .= '<input type="hidden" name="id" value="'. $_GET['id'] . '" />';

      $display .= '<p>';

      $display .= '<table border="1">';

      $display .= '<tr>';

      $display .= '<td>First Name: ' . $record->getField('title') . '</td>';

      $display .= '</tr>';

      $display .= '<tr>';

      $display .= '<td>Last Name: ' . $record->getField('body') . '</td>';

      $display .= '</tr>';

      $display .= '</table>';

      $display .= '<p>';

      $display .= '<input type="submit" name="delete" value="Delete" />';

      $display .= '<input type="submit" name="delete" value="Cancel" />';

      $display .= '</p>';

      $display .= '</form>';

      }

      else

       

       

      # If the user clicks the Delete button delete the record using the function $record->delete();

      # Then display the message to the user that the record was deleted.

       

      {

      if ($_POST['delete'] == 'Delete')

      {

      # delete the record

      $record->delete();

      $display = '<p>The record was deleted successfully.</p>';

      }

       

      # If the users clicks the Cancel button display the message that their action was cancelled.

       

      else

      {

      $display = '<p>Cancel: The record was not deleted.</p>';

      }

       

      # Add the link back to the $display variable for the list view so the user can get back to a new found set of records.

       

      $display .= '<p><a href="delete_record.php">Click here to return to the list view</a></p>';

      }

      ?>

       

       

      <!--

      The form and messages created above are displayed in the $display variable.

      -->

      <html>

      <head>

      <title>Delete Record -> Detail</title>

      </head>

      <?php inlcude('BlogHeader'); ?>

      <div id="paper">

      <?php echo $display; ?>

      </div>

      <?php echo ('BlogFooter'); ?>

      </html>

       

       

      If you don't see anything wrong there, here is my code for the delete form that is posting to the above file:

       

      <?php

      include ("dbaccess.php");

      ?>

       

       

      <?php include('BlogHeader.php');?>

      <div id="paper" class="floatLFT">

      <h1>Delete Record</h1>

      <hr>

      <form action="delete_record.php" method="GET">

      Title: <input name="title" type="text" />

      <br />

      <input name="submit" type="submit" />

      </form>

       

       

       

       

      <?php

       

       

      if(empty($_GET['title']))

      {

      $title = "";

      $request = $fm->newFindAllCommand('BlogPosts');

      }

      else

      {

      $title = $_GET['title'];

      $request = $fm->newFindCommand('BlogPosts');

      $request->addFindCriterion('title', $title);

      }

       

       

      $result = $request->execute();

       

       

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

      echo "<p>Error: " . $result->getMessage() . "</p>";

      exit;

      }

       

      $records = $result->getRecords();

       

       

      echo '<table border="1">

      <tr>

      <th>Title</th>

      <th>Content</th>

      <th>Time Stamp</th>

      <th>Post ID</th>

      <th>Delete Record</th>

      </tr>';

       

       

      foreach ($records as $record)

      {

      echo '<tr>';

      echo '<td>' . $record->getField('title') . '</td>';

      echo '<td>' . $record->getField('content') . '</td>';

      echo '<td>' . $record->getField('timestamp') . '</td>';

      echo '<td>' . $record->getField('postID') . '</td>';

      echo '<td><a href="delete_record_detail.php?id=' . $record->getRecordId() . '">delete</a></td>';

      echo '</tr>';

      }

       

       

      echo '</table>';

       

       

      ?>

      </div>

       

       

      <?php include('BlogFooter.php');

       

      Please let me know what is going on. I've been through 2 books, and I think I'm gaining grey hairs and/or losing hairs...

       

      All graciousness..

        • 1. Re: Delete Record Detail not working
          LyndsayHowarth

          You haven't pinpointed where it is breaking down. PHP has excellent error feedback when you deploy it. Where you have error statements add this before any excit

          echo "<p>Error: " . $result->getMessage() . "</p>";

           

          PHP also processes the code in sequence and shows an error with a line number where the offending code is.

           

          If you are using an old server, you may need an &space in front of the $fm like this

          & $fm->newFindCommand('BlogPosts');

           

          Sometimes the error message does not give enough info about the layout errors in FM. You might have a missing field on the layout or maybe no permission or the behaviour is turned off for browse on a field... It could be many other things like this too. Take it step by step from the top.

           

          - Lyndsay

          • 2. Re: Delete Record Detail not working
            LyndsayHowarth

            When checking, make sure your names exactly match. If you have "Name" in FileMaker for a field name and refer to it as "name" in the layout it will error. The error message for stuff like this is not yet adequate.

            • 3. Re: Delete Record Detail not working
              artdezign

              Hey Lyndsay,

               

              Thanks for the response and advice.  As far as I can tell the problem seems to be occuring around this: if (!isset($_POST['delete']))

              I have been using a simple echo "this spot"; statment to appear in various places to isolate the line that the scripting seems to stop.  I've tried the error handling thing and have never had an error returned to me, even after making sure error handing was turned on with the error_reporting(-1); statement.

               

              The $_POST['delete'] is not set because it won't be set until the if statment has run through itself (the Are you Sure? statements) and then triggered back on itself, but I can't seem to get the script to run through that if statement at all in the first place.  I have made sure that the id value is being past to the detail page, and I have been able to get the detail page to print_r the results to success, but it's lost after that. I did make sure that everything was spelled an capitalized the same in regards to how it is labled in the database itself.

               

              All the code has a logical flow, but why it just gives me a blank page is past me.  I've even tried other various codes suggested from another book, but their code was unable to pass the code in the URL to the next page.   I guess you can say I'm learning a lot here, but I need to find the sucess. 

               

              PHP Version 5.3.6

              Server APIApache 2.0 Handler
              Apache VersionApache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/0.9.8r DAV/2