AnsweredAssumed Answered

php error 500 when using $_POST

Question asked by gageler on Aug 1, 2017
Latest reply on Aug 6, 2017 by gageler

I am new to php and am having trouble getting the FileMaker php API to work when I try to set a search variable based on the value in a form, using $_POST.


The search works fine if I "hardwire" the search using the line:

          $divSearch = 'Legal';



But, I get an "Internal Server error 500" if I try and using the value submitted in the form, using

if ($_POST['submit'] == 'Search') {

$divSearch = $_POST['division'];


$divSearch = 'Legal';



Based on various examples I have seen, I have a tried a range of ways to apply the $_POST information, but every time I include it, I get an error.


Can anyone advise why this might be happening?


Below is the code that fails, with offending lines highlighted in read.




Phillip Gageler






$fm = new FileMaker('PHPSampler', NULL, 'phptest', 'phptest');




<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


<html xmlns="" xml:lang="en" lang="en">


<meta http-equiv="content-type" content="text/html; charset=utf-8" />

<title><?php echo $_SERVER['PHP_SELF'];?></title>

<link rel="stylesheet" type="text/css" href="format.css" />


<body style="background-color:#EFEFEF;">

    <table width="600" cellpadding="0" cellspacing="10" border="0" align="center">


       <!-- header -->

        <tr style="background-color:#6C8EB5;border:1px solid #476898;">

            <td colspan="2" id="main_table_head">


        <font size="3" face="Arial, Helvetica, sans-serif">

<form action="<?php echo $_SERVER['PHP_SELF'];?>" name="searchForm"  method="post">

Division: <input type="text" name="division" id="division" size="40" value="Legal" />

<br />

        <input type="submit" name="submit" id="submit" value="Search" />








if (($_POST['submit'])) {

     $divSearch = $_POST['division'];


     $divSearch = 'Legal';



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


        $find->addFindCriterion('Division', $divSearch);


$find->addSortRule('Last_Name', 1, FILEMAKER_SORT_ASCEND);

$find->addSortRule('Preferred_Name', 2, FILEMAKER_SORT_ASCEND);


        $result = $find->execute();


$foundCount = $result->getFoundSetCount();


$records = $result->getRecords();


$division = $records[0]->getField('Division');



        <tr id="main_table_body">

            <td id="main_table_left">People</td>

            <td id="main_table_right">



            echo '<p class="title">'.$foundCount.' records found for Division = Human Resources';


                <table cellpadding="0" cellspacing="0" border="0" width="100%" align="center">


                        <td width="30%" class="division column_label">Division</td>

                        <td width="35%" class="last_name column_label">Last Name</td>

                        <td width="35%" class="preferred_name column_label">Preferred Name</td>



<?php       foreach($records as $record)


            echo '


                        <td class="division column_data">'.$record->getField('Division').'</td>

                        <td class="last_name column_data">'.$record->getField('Last_Name').'</td>

                        <td class="preferred_name column_data">'.$record->getField('Preferred_Name').'</td>






        <tr id="main_table_footer">

            <td colspan="2" style="height:50px;color:#FFFFFF;font:22px arial bold;text-