-1

I'm using https://github.com/Insightly/insightly-php and having a problem passing a simple variable to a method in it:

require("insightly.php");
$i = new Insightly('my-base64-encoded-api-key');

Do you know why getContacts() doesn't seem to see the variable $lastname here?

Example:

$lastname = $_GET["lastname"];
$contacts = $i->getContacts(array("filters" => array('LAST_NAME=\'$lastname\'')));

If I hard code a name in the array for example:

$contacts = $i-getContacts(array("filters" => array('LAST_NAME=\'Smith\'')));

it accepts it and returns results,

but with the variable $lastname it returns nothing - and there is no error so it must not see it. - It's probably a syntax error on my part but I would appreciate anyone pointing me in the right direction :)

Grokify
  • 15,092
  • 6
  • 60
  • 81
jdailey
  • 19
  • 1
  • 4
    Try using quotation marks (`""`) instead of apostrophes. This may be the problem because PHP interprets anything in apostrophes literally. See: http://stackoverflow.com/questions/3446216/what-is-the-difference-between-single-quoted-and-double-quoted-strings-in-php – bnahin Oct 30 '15 at 16:30
  • Also, switch on error reporting as those lines should produce errors. – vascowhite Oct 30 '15 at 16:32
  • @vascowhite what errors would there be besides `$i-getContacts` which I assume is just a typo? – andrewtweber Oct 30 '15 at 16:59
  • @andrewtweber `array('LAST_NAME=\'$lastname\'')` isn't valid syntax is it? – vascowhite Oct 30 '15 at 17:30
  • Then again, maybe it is https://3v4l.org/qBlD2. My bad. Didn't process the \'s – vascowhite Oct 30 '15 at 17:32

1 Answers1

0

Because you used apostrophes when setting the array, PHP will interpret it as literal text.
Because of this, the array would read:

Array ( [filters] => Array ( [0] => LAST_NAME='$lastname' ) )

$contacts should be defined like this:

$contacts = $i->getContacts(array("filters" => array("LAST_NAME=$lastname")));

See this S.O. thread for more information.

Community
  • 1
  • 1
bnahin
  • 796
  • 1
  • 7
  • 20
  • I tried this syntax : $contacts = $i->getContacts(array("filters" => array("LAST_NAME=$lastname"))); and get : 400 Bad Request The request could not be understood by the server due to malformed syntax – jdailey Nov 02 '15 at 09:10