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

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

Recommended Posts

Posted

I am trying to grab data in a field (USERS::fullName) by doing a search on another field (USERS::accountName). The context is that a person logs into CWP where authentication is via Accounts and Priviledges. Her account name is also in the table USERS (but her password is not). Once I log in I want to go to the USERS table, search for her record, and grab her fullName.

The log in process works properly and is omitted here for brevity. The $_SESSION['accountname'] is set to htmlentities($_POST['accountname']).

Here is how I have it written:


// successfully logged in.  now find specific user based on log in

	$find = $fm->newFindCommand('userListView');

	$find->addFindCriterion('accountName', $_SESSION['accountname'] );

	$result = $find->execute();

	

// check for errors - omitted for brevity



// grab data from other fields in record

	$record = $result->getFirstRecord();

	$field = $record->getField('user_fullname');

	$data = $field->execute();

	var_dump($data);

	exit;





I receive the following error message:





Fatal error: Call to undefined method FileMaker::getFirstRecord() in /Applications/MAMP/htdocs/FMP...

I can run the first block (// successfully logged in. now find...) and var_dump that successfully. Since the log in is successful and I can var_dump the first block, I feel confident that I have an $fm object. Not sure what I am doing wrong in the last block.

Can anyone offer any guidance?

Thanks.

Posted

I found this link , which was helpful. I presumed that since the var_dump worked in the first block that there were no errors. I was mistaken. In fact, the layout was wrong. I had


$find = $fm->newFindCommand('userListView');





instead of 





$find = $fm->newFindCommand('usersListView');





("users" should have been plural).  So, I received a no layout error message.



I fixed that, and added a second error check after the second block of code.  However, it is not working.  My code now looks like this:





// find specific user based on log in

			$find = $fm->newFindCommand('usersListView');

			$find->addFindCriterion('user_user', $_SESSION['username'] );

			$result = $find->execute();



				// check for errors		

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

				    die('
' . $result->getMessage() . ' (error ' . $result->code . ')');

				} else {

				

				// grab data from other fields in record

				$record = $result->getFirstRecord();

				$field = $record->getField('USERS__stu_inv_usr::user_fullname');

				$result = $field->execute();

			

					// check for errors		

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

					    die('
' . $result->getMessage() . ' (error ' . $result->code . ')');

					} else {

					var_dump($result);

					exit;

					}

				}

			}





However, I do not get an error message and an error code.  Instead, I receive the following:





Fatal error: Call to a member function execute() on a non-object in /Applications/MAMP/htdocs/FMP

This is referring to this line (see next post):

Posted


$result = $field->execute();

I'm not sure why the error capturing (FileMaker::isError($result)) is not displaying the error. In any case, I'm not sure what to try next. Can anyone make any suggestions?

(It seems that I can only have four "code" blocks in a post, so I continued in this one.)

Posted

I feel like I'm getting closer. I'm now able to log in with the following:


// find specific user based on log in

	$find = $fm->newFindCommand('usersListView');

	$find->addFindCriterion('user_user', $_SESSION['username'] );

	$result = $find->execute();



// check for errors		

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

	    die('
' . $result->getMessage() . ' (error ' . $result->code . ')');

	}

	

// grab data from other fields in record

	$records = $result->getRecords();



	foreach ($records as $record) {

		$record->getField('user_fullname');

		$_SESSION['fullname'] = $record;

	}





It occurred to me that my $result would be an array of one, so I added the foreach loop.  I tried using the getFirstRecord in a couple of places, but to no avail.



This code does, in fact, log in properly.  Now, my issue is that when I am redirected to the dashboard (automatic via header( 'Location: dashboard.php) I receive this message:





Catchable fatal error: Object of class __PHP_Incomplete_Class could not be converted to string in /Applications/MAMP/htdocs/FMP...

This refers to $_SESSION['fullname'] which is set on index.php (see above) and used throughout (e.g. "Welcome to the Dashboard John Doe").

I keep trudging along - kind of like walking through mud that's thigh high! As always, if anyone has any insights, that would wonderful.

Thanks.

Posted

Fixed! (At least for now).

I changed the foreach loop from this:


foreach ($records as $record) {

	$record->getField('user_fullname');

	$_SESSION['fullname'] = $record;

}





to this:





foreach ($records as $record) {

	$result = $record->getField('user_fullname');

	$_SESSION['fullname'] = $result;

}

That is, I created a variable ($result) to equal the $record object and then assigned $_SESSION['fullname'] to the $result.

Posted (edited)

FYI.. the reason it wasn't working:

Depending on the version of the api you're using, the getFirstRecord method may not actually exist. All it does in any case is returns the first record off the record stack. You can easily accomplish this using native php functions e.g.


<?php

/* Documented method */

$record = $result->getFirstRecord();



/* This, get's you the same as the above */

$record = current($result->getRecords());

You can also of course just loop through the records object, and if there's only one record then it doesn't really make a difference from a performance standpoint, but still... FYI.

Edited by Guest

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