Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 2808 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

I have a PHP page that allows users to search our department directory (of people). It works, but if no records are found, then they get a header graphic and nothing else. I have looked online, and I think my FileMaker::IsError syntax is correct, but it does not display. Would someone look at the attached file and see what I've done wrong? (Once I get it to display an error code, I can customize it and trap for various errors, but right now I only get the header!) Thank you, Brian

namesearch.php

Posted (edited)

There is an example on this page: https://jonathanstark.com/fm/web-publishing-with-filemaker-and-php.php

What you are looking for in this case is the part that gives "No Records Found," but there should really be some sort of $result.count() or similar like in FX.php where there is $result['foundCount'] as foundcount = 0 is not really an error; it's perfectly valid search result.

if (FileMaker::isError($result)) {
    if (! isset($result->code) || strlen(trim($result->code)) < 1) {
        echo '<tr>';
        echo '<td colspan="3">A System Error Occured</td>';
        echo '</tr>';
    } else {
        echo '<tr>';
        echo '<td colspan="3">No Records Found (Error Code: '.$result->code.')</td>';
        echo '</tr>';
    }
} else {
    $records = $result->getRecords();
    foreach ($records as $record) {
        echo '<tr>';
        echo '<td>' . $record->getField('Status') . '</td>';
        echo '<td>' . $record->getField('Type') . '</td>';
        echo '<td>' . $record->getField('Account Name') . '</td>';
        echo "</tr>";
    }
}

 

Edited by ggt667
Posted

Thank you for the link! I modified the FileMaker::isError code, but the behavior is still the same. I also moved where the error is called on the page (attached). On the server I see a 401 error in the logs... Why does it bomb out when there is an error? Thank you, Brian

namesearch.php

Posted

Does the following output anything?

<?php
echo "Code: " . $result->code; 
#Check for an error
if( FileMaker::isError( $result ) ) {
?>

 

Posted

With the open brace, the page fails entirely.

Without the brace, it loads on a found set, but only says "Code: " without any code number.

When no records are found, I get the header and nothing else (the "Code: " is not present!).

Posted

If I were you I'd create a new file with the following( still from the same link ) and adapt this to my database settings. To see if I could learn anything from this setup.

<?php

require_once ('Filemaker/Filemaker.php');
$fm = new FileMaker('TimeTracker.fp7', '127.0.0.1', 'esmith', 'f!r3crack3r');
$request = $fm->newFindAllCommand('associate_layout');
$request->addSortRule('Status', 1);
$request->addSortRule('Type', 2);
$request->addSortRule('Account Name', 3);
$result = $request->execute();

echo '<table border="1">';
echo '<tr>';
echo '<th>Status</th>';
echo '<th>Type</th>';
echo '<th>Account Name</th>';
echo '</tr>';
if (FileMaker::isError($result)) {
    if (! isset($result->code) || strlen(trim($result->code)) < 1) {
        echo '<tr>';
        echo '<td colspan="3">A System Error Occured</td>';
        echo '</tr>';
    } else {
        echo '<tr>';
        echo '<td colspan="3">No Records Found (Error Code: '.$result->code.')</td>';
        echo '</tr>';
    }
} else {
    $records = $result->getRecords();
    foreach ($records as $record) {
        echo '<tr>';
        echo '<td>' . $record->getField('Status') . '</td>';
        echo '<td>' . $record->getField('Type') . '</td>';
        echo '<td>' . $record->getField('Account Name') . '</td>';
        echo "</tr>";
    }
}
echo '</table>';

?>

 

Posted

Thank you. I think it is now resolved. I "flipped" the code (before it was html with php, now it is php with html echoed), and found that the getRecords at the beginning of the file was creating a PHP FATAL error. Once that was moved to the else (like in your example), I stopped getting the FATAL error and got the 401 error I expected. Once again, thank you for your help!  Brian

This topic is 2808 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.