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

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

Recommended Posts

Posted

I am trying to use the FMNew Fuction to create a new record but am encountering problems. Just as Mariano said, the examples that come with the FX.php package are old and outdated so maybe that is why the fuction list is out of date as well. I am having trouble with the $InstanceName and the $Query. What's the diffrence? Mariano uses the $Query in his samples. Also when I use the AddDBPParam('FirstName',$firstName) it responds with an error stating that I have used an invalid function. What am I to put in the 'FirstName' spont as well as the $firstName? Is the first just the field name or either what you want the new record to have in that field? For the second is it just the field name again?

Justin Grewe

Posted

Note: The example Justin mentioned can be found at

http://www.fmforums.com/threads/showflat.php/Cat/0/Number/93775/page/0/view/collapsed/sb/5/o/all/fpart/1#93810

($query = new FX("127.0.0.1", "591"):

The following line of code is from the FXFunctions.rtf documentation that is included in the FX download:

$InstanceName = new FX('127.0.0.1');

Short Answer

$query and $InstanceName are just variable names that refer to the instance of FX that you created. They are like field names - you can name them whatever you like, so long as they are not key words. It is standard in most languages to begin variable names (like $query) with a lower case letter, and to begin class names (like FX) with a capital letter.

AddDB[color:"red"]PParam('FirstName',$firstName)

This won't won't work because you have an extra "P" in there. Check if that is the case in your code. If it was just a typo in the posting, check the following:

  • Your statement must end with a semicolor (:
  • Make sure that you've created an instance of the FX class first: $q = new FX();
  • Make sure that you are calling the method on the instance: $q->AddDBParam('FirstName', $firstName);

I'm not sure what else to tell you to check at this point. If those ideas don't solve it, post a snippet of your code so we can take a closer look at what the problem might be.

Long Answer

In PHP, variables are identified by the "$" symbol. "InstanceName" is just a name given to the variable which references the new instance of the FX class that is stored in memory. "$InstanceName" is not a key word, and does not have special meaning to the PHP parser, other than being the name of a variable the programmer has created. You can name this variable anything you like. In my example I used a variable named "$query" to hold the new instance of FX. You could just as well name it $q to keep your code shorter.

Technically, you can simply write

new FX('127.0.0.1');

This example creates a new instance of the FX class, but doesn't provide any way to refer to it -- the object would exist in memory but you wouldn't have any programmatic way of accessing it. When you instantiate a class, a reference to the new object is returned. You assign that reference to a variable, so you can use the object later. That's why you see:

$InstanceName = new FX('127.0.0.1');

"new FX()" returns a value. That value is a reference to an object in memory. That reference can be assigned to a variable using "=". In this case, the author assigned the reference to a variable named $InstanceName.

Once we have a reference to an object, we can invoke methods on the object. Methods are just functions that are tied to a class. When you instantiate an object, the object has access to the functions that are defined for it's class. Functions that are defined for the class are called its "methods". Here is an example that creates myCar as an instance of Car, and then tells myCar to start it's engine:

$myCar = new Car();

$myCar -> startEngine();

In this example, startEngine() is one of Car's methods. That is, Car defines a function named startEngine, which becomes available to any objects that are created of type Car. $myCar references an object of type Car, and can therefore call the startEngine() method of Car.

You could not write:

startEngine();

This would fail because (presumably) there is no public function named "startEngine()". There is only a method named "startEngine()", which is defined for the "Car" class. Methods must be called upon objects. This means you must call the "startEngine()" method on a valid instance of Car, like so:

$myCar = new Car(); [color:"silver"]// create an instance of Car

$myCar->startEngine(); [color:"silver"]// call the startEngine method on myCar, which is a Car type

$yourCar = new Car(); [color:"silver"]// create another instance of Car

$yourCar->startEngine();[color:"silver"]// call the startEngine method on yourCar, which is a Car type.

Posted

By the way, it is a good idea to learn PHP by reading a book on it before you get too far along. It will help you build a better foundation for your applications. You don't have to read an entire 1,000 page book, just a few key chapters. The following excerpt is from a previous posting:

http://www.fmforums.com/threads/showflat.php/Cat/0/Number/93508/page/0/view/collapsed/sb/5/o/all/fpart/all/vc/1#93684

PHP can be a bit daunting at first, and I do recommend reading a book on the language to get you started in the right direction. I started with Wrox's Professional PHP 4 and have been very happy with it. There are really only a few chapters (roughly 100 pages) you have to read to gain a good understanding of the PHP syntax (the chapters on PHP Fundamentals, PHP Structures, Object Oriented Programming with PHP, and Sessions and Cookies). I've also read the O'Reilly book on PHP (by Rasmus Lerdorf, the creator of PHP) and liked it, although I found the Wrox book much more helpful.
Posted

I am trying to add a new record in the database and I am wondering why this code will not work. First the html page which calls upon the php, then the php code:

html:

<html>

<title>Test</title>

<body>

<h2><center>Test</center></h2>

<form action="displayFXDatabaseList2.php" method="post">

<b>Registration ID:</b>

<input name="RegistrationID" type="text" value=""/>

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

</body>

</html>

php:

<?

require_once("FX.php");

$query=new FX("127.0.0.1","591");

$query->setDBData("Evalrespond.fp5","AdminRespond");

$query->AddDBParam('RegistrationID', $_REQUEST['RegistrationID']);

$ReturnedData=$query->FMNew();

?>

Thanks.

Justin Grewe

Posted

You know what I think it is, maybe because I don't have curl installed? Does anyone have a good resource about how to go about installing and configuring curl? Also, do you think I need it?

Thanks.

Justin Grewe

Posted

Well, FX is supposed to "check for cURL support and do a POST with sockets if it is not present." This is from the CHANGES.txt file included with the FX download, in the July 2003 section.

Are you sure that cURL is not installed? Have you checked this using phpinfo()?

I have PHP version 4.2.3 installed on my computer (Win2K Pro, IIS ), and PHP indicates that cURL is installed and enabled. What version of PHP are you using? Did you use the PHP installer, or did you do a manual installation of the DLLs, etc?

Instead of using cURL, you could instruct FX to use POST via sockets:

query->FMUseCURL(false);

Or you could instruct FX to use GET instead, using

query->FMPostQuery(false);

However, POST requests support longer HTTP requests than do GET requests, so you're safer using POST. According to the documentation in the FX download (FXFunctions.pdf), "if there are several calls to FileMaker from a single page using sockets may result in the truncation of your data." For this reason, I'd suggest using cURL. Also, I believe that using cURL could ultimately allow you to program the timeout, so that your page can respond gracefully if FileMaker has become unavailable (due to a server backup, crash, dialog box open on the FileMaker application, etc). I haven't used this feature myself but I think this would only be available through the use of cURL.

I am wondering why this code will not work

Could you elaborate on how you know that this code isn't working? Is an error message displayed in the browser? If so, what is it? Is a record being inserted in FileMaker, but without the appropriate RegistrationID? Or is the record not even being created? Can you check the Access.log in the FileMaker directory (in Program Files) - what do the last requests to FileMaker look like? What HTTP code is FileMaker returning (the HTTP code is the penultimate word on each line in the log, and is usually a number like 200, 400, etc).

Posted

Mariano,

I have checked the phpinfo() and it doesn't even talk about curl once. I'm guessing this is an indication that I do not have it?

Also, where is the Access.log that you were talking about? I have searched my whole computer and could not find it.

Justin Grewe

Posted

If phpinfo() doesn't have a section titled cURL then it is not installed. To install it, follow the instructions at the bottom of the post.

Even if cURL is not installed, the FX module should still work. I don't have cURL installed on my home computer, and the current version of FX works just fine. Is your "displayFXDatabaseList2.php" file inside the FX folder? If not, then the problem is with the [color:"green"]require_once("FX.php"); statement. You'll have to update it so that it references the correct location of the FX file. If the FX folder is in the same directory as the your "displayFXDatabaseList2.php" file, then you could change your require statement to [color:"green"]require_once("FX/FX.php");. This is just like linking to an HTML page -- you have to set the path to the linked page correctly, based on the location of the current page. This may very well be the problem.

While FX works without cURL, it is better to use cURL to avoid potential problems with sockets ("if there are several calls to FileMaker from a single page using sockets may result in the truncation of your data").

The Access.log file I referred to is the web access log maintained by FileMaker. It records all requests received by the Web Companion in Common Log Format. A description of the Common Log Format can be found at: http://www.w3.org/Daemon/User/Config/Logging.html#common-logfile-format . Each HTTP server on your machine maintains an Access log, so you should have one for FileMaker and another for IIS (or Apache). The FileMaker access log is stored in a directory such as: C:Program FilesFilemakerFilemaker 6Access.log. This file does not exist by default and is not created created until the Web Companion is enabled and receives its first HTTP request.

Hmm. This leads me to another question: When running the example, do you have the FileMaker applicattion open and Web Companion enabled? Which port is web companion configured to listen on? Is the particular .fp5 file you want to access open and enabled for web sharing (File > Sharing > Web Companion)?

HOW TO INSTALL cURL

There are four main steps to installing the cURL library:

1. Make the cURL library available to PHP. This is done by copying the php_cURL.dll to the System32 directory.

2. Make the supporting cURL libraries available to PHP. This is done by copying the supporting .dll files to the System32 directory.

3. Configure PHP to use cURL.

4. Reload PHP. This is done by restarting the web server (IIS, Apache, etc.).

1. Make cURL available to PHP

Open the PHP extensions folder. This is probably located at C:phpextensions or C:php4extensions.

Open the Windows system32 folder. This is probably located at C:WINDOWSsystem32 or C:WINNTsystem32.

Copy the following file from the PHP extensions folder to the system32 folder:

-php_curl.dll

2. Make the supporting cURL libraries available to PHP

Open the PHP dlls folder. This is probably located at C:phpdlls or C:php4dlls.

Copy the following files from the PHP dlls folder to the system32 folder:

-libeay32.dll

-ssleay32.dll

3. Configure PHP to use cURL

Open the php.ini file, probably located at C:WINDOWSphp.ini or C:WINNTphp.ini.

Search for "curl".

Find the line: ;extension=php_curl.dll

Remove the leading ";"

4. Reload PHP

Restart the HTTP server. You'll probably have to go through Start > Control Panel > Administrative Tools to do this. If you are using IIS, you can open the "Internet Information Services" link and restart IIS from there. If you are using Apache, you'll probably have to open the Services link and right click on the Apache service to restart it.

To check that PHP successfully loaded cURL, run the phpinfo() script again. The output of phpinfo() should now include a section for cURL, indicating that cURL is enabled and the cURL version number.

Posted

By the way, here is a copy of your code, rewritten so that it only uses one file (1 php file, as opposed to 1 html and 1 php file):


<html>

<title>Test</title>

<body>



<?

if ($_REQUEST["RegistrationID"]) {

	require_once("FX/FX.php");

	$query = new FX("127.0.0.1", "591");

	$query->setDBData("Evalrespond.fp5", "AdminRespond");

	$query->AddDBParam("RegistrationID", $_REQUEST["RegistrationID"]);

	$ReturnedData = $query->FMNew();

	

	if (!$ReturnedData["errorCode"]) {

		print "Inserted record.";

	}

	else {

		print "Error: ".$ReturnedData["errorCode"];

	}

	print "<br><hr>n";

}

?>



<h2><center>Test</center></h2>

<form action="<?=$_SERVER["SELF"]?>" method="post">

<b>Title:</b>

<input name="RegistrationID" type="text" value=""/>

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

</body>

</html>

Posted

Mariano,

I have the everything in the FX folder. Also I have tried your example where everything is on one page and I get an error when I submit it. It says Resource not allowed and in the url at the top I get this back:

http://localhost/FX/<br%20/><b>Notice</b>:%20%20Undefined%20index:%20%20SELF%20in%20<b>C:/Program%20Files/FileMaker/FileMaker%20Pro%206/Web/FX/displayFXDatabaseList2.php</b>%20on%20line%20<b>24</b><br%20/>

Is the problem with the server.php file?

It still does not submit anything into the filemaker database.

Justin Grewe

Posted

Mariano!

I got it. Another dumb mistake. In my first post with code I did not have the right database, Evalrespond.fp5. It is really Evalrespond1.fp5. Thanks for your help. I think I will go ahead and install cuRL though.

Justin Grewe

Posted

One quick question though,

When you are using FX.php with multiple databases and layouts do you have to create multiple FX.php's with diffrent database parameters? For instance, I am creating another FX.php but with the filename FX2.php and then when I use it I call upon it with this name. Is this the correct way of going about it.

Thanks.

Justin Grewe

Posted

No, FX is a class library and you shouldn't touch the FX file or anything in the FX class. To sends commands to multiple FileMaker files from the same PHP script, you just need to create a new instance of FX and set the new instance to use the appropriate file using the SetDBData method:

$query = new FX("127.0.0.1", "591");

$query->SetDBData("myOtherFile.fp5", "myOtherLayout");

$query->AddDBParam("field", "value");

$result = $query->FMNew();




You actually don't even need to create a new instance of FX - you can just call SetDBData again on an existing instance of FX.  Continuing with the code above you could use the same instance of FX to create a new record in "yetAnotherFile.fp5": 




$query->SetDBData("yetAnotherfile.fp5", "andAnotherLayout");

$query->AddDBParam("field", "value");

$result = $query->FMNew();

In this example, you've overridden the $result variable. This is perfectly OK - unless you need to access the results from the first call to FMNew() later on. If you wanted to keep both results, you could name the second $result variable something different, like $result2 or $resultYetAnotherFile.

Here is an example that adds three new records to the demo database that comes with FX (Book_List.fp5), and one new record to another database I created (roster.fp5).

<?

require_once("FX/FX.php");

$q = new FX("127.0.0.1", 591); [color:"green"]//Creates an instance of the FX class

$q->SetDBData("Book_List.fp5", "Detail_View"); [color:"green"]//Sets the instance of the FX class in $q to use Book_List.fp5

$q->AddDBParam("title", "book number 1");

$r = $q->FMNew();

$q->AddDBParam("title", "book number 2");

$r = $q->FMNew();

$q->AddDBParam("title", "book number 3");

$r = $q->FMNew();

$q->SetDBData("Roster.fp5", "web"); [color:"green"]//Sets the instance of the FX class in $q to use Roster.fp5

$q->AddDBParam("name", "mariano peterson");

$r = $q->FMNew();

?>

Posted

By the way, [color:"gray"]require_once("FX.php"); doesn't create an instance of FX. Rather, it loads the blue prints that define the FX class. The [color:"gray"]new FX() statement actually creates an FX object, based on the blue prints found in the FX class definition (in FX.php). Hope this helps.

Posted

Mariano,

Just another quick question, I am working my way up transforming my xsl pages to php and with the logon, I have it search for records in the student database, the action of that form being the php which does the find. Then on the loggedin.php I am needing to transfer a field that is in the found records to use it as another find in another database. I have tried a meta refresh to go to that other php page using that database, and try to transfer that field in the url using <? $_REQUEST["PIDM"] ?> but withoug success. Is there a way of doing this and also do I need to have seperate pages for doing all of these processes?

Thanks,

Justin Grewe

Posted

I have the main php file where it will create multiple records and then edit them and am having parsing problems even though it all seems right.

<?

if($_REQUEST['Submit'])

{

require_once("FX.php");

$query = new FX("127.0.0.1", "591");

$query->setDBData("Questions1.fp5", "Main");

$ReturnedData = $query->FMFindall();

foreach($ReturnedData['data'] as $key => $value)

{

$query -> SetDBData ("Evalrespond1.fp5", "AdminRespond");

$query -> AddDBParam ("RegistrationID",

$_REQUEST['RegistrationID']);

$query -> AddDBParam ("QuestionID",

$value['QuestionID'][0]);

$query -> FMNew();

}

}

if($_REQUEST['form2'])

{

foreach($_REQUEST['-recid'])

{

$query -> SetDBData ("Evalrespond1.fp5", "AdminRespond");

$query -> AddDBParam ("RegistrationID", $value['RegistrationID'][0]);

$ReturnedData =$query -> FMFind();

$query -> AddDBParam ("-recid", $_REQUEST['-recid']);

$query -> AddDBParam ("MultipleChoiceResponse",

$_REQUEST['MultipleChoiceResponse']);

$query -> AddDBParam ("ShortAnswerResponse",

$_REQUEST['ShortAnswerResponse']);

$ReturnedData = $query -> FMEdit();

}

$query -> SetDBData ("Evalrespond1.fp5", "AdminRespond");

$query ->AddDBParam ("RegistrationID", $value['RegistrationID'][0]);

$ReturnedData =$query -> FMFind();

}

}

?>

<html>

<title>Your Questions</title>

<body>

<h1><b><center>Your Questions</center></b></h1>

<? foreach($ReturnedData['data'] as $key => $value)

{

echo "<form action="http://localhost/FX/Evalrespond2.php" method="post">";

echo $value['QuestionID'][0];

echo "<br>";

echo $value['QuestionsQuestionID::Question'][0];

echo "<br>";

echo "Your response:";

echo "<br>";

if($value['Type'][0]==0)

{

echo "<input type="textarea" name="ShortAnswerResponse" value=""/>";

echo "<br>";

}

if($value['Type'][0]==1)

{

echo "1";

echo "<input type="radio" name="MultipleChoiceResponse" value="1"/>";

echo "2";

echo "<input type="radio" name="MultipleChoiceResponse" value="2"/>";

echo "3";

echo "<input type="radio" name="MultipleChoiceResponse" value="3"/>";

echo "4";

echo "<input type="radio" name="MultipleChoiceResponse" value="4"/>";

echo "5";

echo "<input type="radio" name="MultipleChoiceResponse" value="5"/>";

}

echo "<input type="hidden" name="-recid" value=";

echo """;

echo $value['CurrentRecID'];

echo """;

echo "/>";

echo "<input type="submit" name="form2" value="submit"/>";

echo "</form>";

} ?>

And the error I get is unexpected ")" found on line 18.

Any help would be GREATLY appreciated.

Justin Grewe

Posted

Re: Logon

Remember, using PHP you can send a command to one database, then another command to another database, and so on. You only have to pass data to another PHP script if you need to pause in between the two commands to gather more user input.

If you do need to pass data from PHP script to the next, the way to do this is with sessions. Sessions allow you to store data on the server, and have it automatically loaded back up and available to you the next time the user hits your server. There are some details you should probably read more about, but that it the gyst. ( wink.gifuhem... these details are covered quite nicely in the Wrox PHP4 book I've plugged several times now, specifically in on the chapters I mentioned as a must-read, the chapter on Sessions and Cookies wink.gif ). PHP has a particularly pleasant, flexible, and easy to use implementation of sessions. Sessions are extraordinarily useful when programming a web solution such as an intranet or shopping cart that records user preferences and selections as they move through the application (such as logged in status). Reading about how sessions work and how to use them is really worthwhile. If you devote a weekend to it (or maybe just a day), you should be able to plow through the most fundamental aspects of PHP in the Wrox PHP4 book. See my summary on which chapters are probably the most important to read through first:

http://www.fmforums.com/threads/showflat.php/Cat/0/Board/UBB12/Number/93508/page/0/view/collapsed/sb/5/o/o/fpart/all#93684 . This is not to say that the other information is not important; its just that the chapters I point out are the ones you'll most likely refer to the most often, and will help give you a better understanding of the PHP paradigm (particularly important to FileMaker developers who are used to a very different paradigm).

Anyway, here is an example of how to set a session variable on page 1, and retrieve that variable on page 2:


First Page:

<?

session_start();

$_SESSION["PIDM"] = "some value";

?>



Second Page:

<?

session_start();

print $_SESSION["PIDM"];	// prints "some value"

?>

This topic is 7562 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.