We help IT Professionals succeed at work.

Update FileMaker Database  API PHP Code to Retrieve Query String

smower
smower asked
on
1,602 Views
Last Modified: 2014-01-15
Hello,

I have a little php site created by a wizard software that pulls data out of FileMaker.  I have a current page that currently retrieves the record id out of the url to look up the database record and display the fields from the record.  I want to make a slight modification that will allow me to instead send a PO parameter that would instead look up the record by the PO number instead of the record id when PO=12345 is sent in the query string.  I still want the existing functionality but need to know how to make it either look up record id or po number.  Here is the existing php section that pulls out the record id.

<?php

    /**
    * FileMaker PHP Site Assistant Generated File
    */

    require_once 'fmview.php';
    require_once 'FileMaker.php';
    require_once 'error.php';

    $cgi = new CGI();
    $cgi->storeFile();
   
    $databaseName = 'SalesFM7';
    $layoutName = 'XSLEditLayout';

    $userName = $cgi->get('userName');
    $passWord = $cgi->get('passWord');

    $fm = & new FileMaker();
    $fm->setProperty('database', $databaseName);
    $fm->setProperty('username', $userName);
    $fm->setProperty('password', $passWord);
   
    ExitOnError($fm);
    $layout = $fm->getLayout($layoutName);
    ExitOnError($layout);

    // formats for dates and times
    $displayDateFormat = '%m/%d/%Y';
    $displayTimeFormat = '%I:%M:%S %P';
    $displayDateTimeFormat = '%m/%d/%Y %I:%M:%S %P';
    $submitDateOrder = 'mdy';

    $recid = $cgi->get('-recid');
    if (!isset($recid))
        $recid = 1;
    $record = $fm->getRecordById($layoutName, $recid);
    ExitOnError($record);
   
    class EmptyRecord {
        function getRelatedSet($relationName) {
            return array(new EmptyRecord());
        }

        function getField($field, $repetition = 0) {
        }

        function getRecordId() {
        }
    }
   
?>

Open in new window

In slight testing on a test page it seems like the following type of code is needed to pull a po number:

$cmd =& $fm->newFindCommand('XSLLayout');
$cmd->addFindCriterion('PO', $_REQUEST['PO']);
$result = $cmd->execute();
if (FileMaker::isError($result)) {
    echo 'unable to find PO: ' . $result->message . '(' . $result->code . ')';
    die();
}
$records = $result->getRecords();

Open in new window

Does anyone know how to tweak these two pieces of code to work together to make my page a little more dynamic in allowing me either url search?

http://myipaddress/Folder/editrecord.php?PO=12346

or

as is working currently only:

http://myipaddress/Folder/editrecord.php?-action=browse&-recid=5138

Thanks in advance,
Shawn
Comment
Watch Question

Commented:
Do something like this around line 35 in the first block:

$recid = $cgi->get('-recid');
$recpo = $cgi->get('PO');
if (!isset($recid) && !isset($recpo)) {
   $recid = 1;
}
if (isset($recid) {
    $record = $fm->getRecordById($layoutName, $recid);
    ExitOnError($record);
} else {
    $cmd =& $fm->newFindCommand('XSLLayout');
    $cmd->addFindCriterion('PO', $recpo);
    $result = $cmd->execute();
    if (FileMaker::isError($result)) {
        echo 'unable to find PO: ' . $result->message . '(' . $result->code . ')';
        die();
    }
    $records = $result->getRecords();
    $record = array_pop($records);
}

Open in new window

Author

Commented:
Thanks, I tried it but it doesn't find the record when searching by po still.  It does still find the recid.

Commented:
It depends if you have both -recid and PO parameters in your URLs. You may want to reverse the code to have PO takes precedence over -recid when testing with isset(). Also, maybe you're missing some parameters in the URL to trigger the code, have you tried adding the "-action=browse" parameter? For instance:

http://myipaddress/Folder/editrecord.php?-action=browse&PO=12346

Author

Commented:
Thank you.  You may be onto something.  I just am not that proficient with php code.  I did the -action=browse and then put the po code in both places and removed the recid code and then it searches by po.  I tried to put it back and now it is giving me php errors on the recid version saying undefined variable.  Do you know precisely how the code should look to just expect one or the other but not both?  I assume the code  with the && is looking for both at the same time?

Thanks,
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Thank you.  Now I finally understand what the exclamation point is doing.  It is a negative operator saying this "is not".  Correct?

Anyway I updated the code and now it partially works.  If I start with a rec id it will pull up the item by recid. If I then change it to a po it will pull up the po which is good.  However if I then try to pull up something by recid again it just defaults to the last po everytime and will no longer let me look up something by recid unless I log out and then log back in and search by recid again?  Any ideas how to fix that?

Thanks,
Shawn
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
It seems to be working with those changes.

Thank you!

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.