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'];

else

$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.

 

Thanks

 

Phillip Gageler

----------------------------------------------------

<?php

 

require_once('FileMaker.php');

 

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

 

?>

 

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

        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>

<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" />

</head>

<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" />

      

</form></font>

            </td>

        </tr>

 

<?php

 

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

     $divSearch = $_POST['division'];

    else

     $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">

 

            <?php

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

            ?>

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

                    <tr>

                        <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>

                    </tr>

 

<?php       foreach($records as $record)

      

            echo '

                    <tr>

                        <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>';

?>         

                </table>

            </td>

        </tr>

        <tr id="main_table_footer">

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

align:center;">footer</td>

        </tr>

    </table>

</body>

</html>

 

---------------------------------------------------

Outcomes