PHP 8.1 error with "Get Options From MySQL Query"

3 posts by 2 authors in: Forums > CMS Builder
Last Post: May 25, 2022   (RSS)

By dbown - May 24, 2022

There appears to be a problem using the "Get Options From MySQL Query" when running on PHP 8.1 or PHP 8.0.

I have followed the directions in this post: https://www.interactivetools.com/forum/forum-posts.php?postNum=2232462#post2232462

I have created a section editor for Documents where I can create a document and assign it to a particular Client and then using "Get Options From MySQL Query" I can then select which Facility (of that client) that this document is meant for. It works just like the Make, Model, Bike example described in that other post.

My Get Options From MySQL Query code reads as follows...

SELECT num, title FROM `<?php echo $TABLE_PREFIX ?>facilities` WHERE clientname = '<?php echo $ESCAPED_FILTER_VALUE ?>'

This setup works perfect when I am running on PHP 7.4 but when I switch to PHP 8.1 it fails.

The PHP 8.1 error message I see on the screen is...

Error: in_array(): Argument #2 ($haystack) must be of type array, string given
in /home1/XXXXX/public_html/cmsb/lib/menus/default/actionHandler.php on line 115.

Is there a fix I can use for this particular issue?

Cheers,

Dave

Attachments:

php81-error.jpg 247K

By daniel - May 24, 2022

Hi dbown,

This is an error we're aware of and there should be a fix coming in the next release of CMSB. In the meantime, can you try out this fix?

In /cmsb/lib/menus/default/actionHandler.php on line 115, replace this:

    $selectedAttr = ($value == @$_REQUEST['selectedValue'] || @in_array($value, $_REQUEST['selectedValue'])) ? 'selected="selected"' : '';

with this:

    $selectedAttr = ($value == @$_REQUEST['selectedValue'] || (is_array($_REQUEST['selectedValue']) && in_array($value, $_REQUEST['selectedValue']))) ? 'selected="selected"' : '';

Let me know if that fixes the issue, or if you have any other questions.

Thanks!

Daniel
Technical Lead
interactivetools.com