Post data from a PHP form to a File Maker database on File maker pro 12 server

Audo picture Audo · Jan 17, 2013 · Viewed 7.1k times · Source

Ok so here is the challenge. I have a File maker database on a Filemaker 12 server hosted on a windows box. I also have a PHP form hosted on a Linux box. How do I get the data from the PHP form to the Filemaker database? Here is what I have tried.

<?php
define('fm_host', '131.181.###.###');
define('fm_file', 'name of the db');
define('fm_user', 'user');
define('fm_pass', 'password');
$layout_name = 'Request'; 
$respondent_data = array("stuff","stuff","stuff","stuff","stuff");
require_once ('FileMaker.php');
$fm = new FileMaker(fm_file, fm_host, fm_user, fm_pass);
if(FileMaker::isError($fm)){ 
die('Error - ' . $fm->getCode() . ' ' . $fm->getMessage());
}
$newAdd =& $fm->newAddCommand('Request', $respondent_data);
$result = $newAdd->execute();
?>

This completes with out error yet when I go to Filemaker pro and open up the copy of the database I download form the server using the Filemaker admin console there is no new record. I have unpacked the Filemaker standalone PHP API in the same directory as the form and it manages to use the Filemaker.php functions. So i'm confused as to why their is at least no error thrown. But at this stage of the project I don't care I just want the data in the database by any means! Any hack will do as the scope of the project ends with the data in the database.

Side notes: I have tried ODBC to access DB and considered manual import using file maker pro but PHP installed on the Linux server is missing a com class in the php.ini file and I don't have access to change this.

I have also considered the same thing using XML though i'm not up to speed with it. But like a drunk at 4am, i'm willing to give it a try.

Thanks in advance!

Answer

Kalle Samuelsson picture Kalle Samuelsson · Jan 21, 2013

You need to map fieldnames to the values in the array $respondent_data. Simple key=>value programming style.

$respondent_data = array("field1" => "stuff", "field2" => "stuff", "field3" => "stuff", "field4" => "stuff", "field5" => "stuff");

You can also specify field by field if you want to, like this

$fm = new FileMaker(fm_file, fm_host, fm_user, fm_pass);
$cmd = $fm->newAddCommand($layout_name);
$cmd->setField("fieldname", "Value");
$cmd->setField("fieldname2", "Value2");
$cmd->setField("fieldname3", "Value3");
$result = $cmd->execute();

if(FileMaker::isError($result)){ 
    die('Error - ' . $fm->getCode() . ' ' . $fm->getMessage());
}  

There is no need to call the FileMaker::IsError method before you call $fm->execute(). Thats when PHP uses cURL to query WPE in FileMaker Server. You will get either a FoundSet-Object or Error-Object returned. IsError is a simple way to see if WPE returned an error a set of records.

For more info http://www.filemaker.com/support/product/docs/12/fms/fms12_cwp_php_en.pdf