AnsweredAssumed Answered

Delete Record Detail not working

Question asked by artdezign on Dec 8, 2012
Latest reply on Dec 12, 2012 by artdezign



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:







include ("dbaccess.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']);





# 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>';





# 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


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



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




$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.




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


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

<div id="paper">

<?php echo $display; ?>


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




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



include ("dbaccess.php");




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

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

<h1>Delete Record</h1>


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

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

<br />

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











$title = "";

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




$title = $_GET['title'];

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

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




$result = $request->execute();



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

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




$records = $result->getRecords();



echo '<table border="1">




<th>Time Stamp</th>

<th>Post ID</th>

<th>Delete Record</th>




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>';







<?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..